Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 /**
  * @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();
     });
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 /**
  * Add the token authentication as default header to the client.
  */
 public function enableTokenAuthentication($token)
 {
     $this->client->setDefaultOption('request.options/headers/Authorization', 'token ' . $token);
 }
Exemplo n.º 5
0
 /**
  * @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));
 }
Exemplo n.º 6
0
 /**
  * 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);
 }