public function enableOAuth2Authentication($clientId, $clientSecret, $accessToken, $refreshToken) { $this->clientId = $clientId; $this->clientSecret = $clientSecret; $this->accessToken = $accessToken; $this->refreshToken = $refreshToken; $this->client->setDefaultOption('request.options/headers/Authorization', 'Bearer ' . $this->accessToken); }
/** * @param string $accessToken * @param ClientInterface $client (optional) * @param ExceptionInterface $exception (optional) */ public function __construct($accessToken, ClientInterface $client = null, ExceptionInterface $exception = null) { $that = $this; $this->client = $client ?: new Client(); $this->exception = $exception; $this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $accessToken))->setDefaultOption('events/request.complete', function (Event $event) use($that) { $that->handleResponse($event); $event->stopPropagation(); }); }
public function enableOauthAuthentication($key, $secret, $accessToken = null, $code = null) { $this->key = $key; $this->secret = $secret; $this->accessToken = $accessToken; $this->code = $code; if (!$accessToken && !$code) { throw new InvalidArgumentException(sprintf("No OAuth code or access token given, please visit %s to generate a new code", "https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id={$key}")); } elseif (!$accessToken && $code) { $request = $this->client->post('oauth2/token', array(), array('code' => $this->code, 'grant_type' => 'authorization_code', 'client_id' => $this->key, 'client_secret' => $this->secret)); try { $response = $request->send(); } catch (ClientErrorResponseException $e) { $this->handleBadResponseExceptions($e); } $token = $response->json(); $this->accessToken = $token['access_token']; } $this->client->setDefaultOption('request.options/headers/Authorization', 'Bearer ' . $this->accessToken); }
/** * Add the token authentication as default header to the client. */ public function enableTokenAuthentication($token) { $this->client->setDefaultOption('request.options/headers/Authorization', 'token ' . $token); }
/** * @param string $token * @param ClientInterface|null $client */ public function __construct($token, ClientInterface $client = null) { $this->client = $client ?: new Client(); $this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $token)); }
/** * Constructor. * * @param string $token Access Token * @param ClientInterface|null $client Client Instance */ public function __construct($token, ClientInterface $client = null) { $this->client = $client ?: new Client(); $this->client->setDefaultOption('headers/access_token', $token); }