protected function loadToken()
 {
     // Carregar token da sessão
     $this->token = \Session::get('oauth_token');
     // Verificar se token foi gerado
     if (is_null($this->token)) {
         return;
     }
     // Verificar se token jah expirou, se sim tentar atualizar o token
     if ($this->token->hasExpired() && is_null($this->token->getRefreshToken()) != true) {
         $this->token = $this->provider->getAccessToken('refresh_token', ['refresh_token' => $this->token->getRefreshToken()]);
         \Session::set('oauth_token', $this->token);
     }
 }
 /**
  * @return string Actual refresh token
  * @throws FitbitTokenMissingException
  */
 public function getRefreshToken()
 {
     if (empty($this->access_token)) {
         throw new FitbitTokenMissingException();
     }
     return $this->access_token->getRefreshToken();
 }
 /**
  * Query to insert a profile record.
  *
  * @param string                 $guid
  * @param string                 $provider
  * @param string                 $resourceOwnerId
  * @param AccessToken            $accessToken
  * @param ResourceOwnerInterface $resourceOwner
  *
  * @return \Doctrine\DBAL\Query\QueryBuilder
  */
 public function queryInsert($guid, $provider, $resourceOwnerId, AccessToken $accessToken, ResourceOwnerInterface $resourceOwner)
 {
     if ($guid === null) {
         $guid = $this->getGuidV4();
     }
     return $this->getQueryBuilder()->insert($this->tableNameProvider)->values(['guid' => ':guid', 'provider' => ':provider', 'resource_owner_id' => ':resource_owner_id', 'refresh_token' => ':refresh_token', 'lastupdate' => ':lastupdate', 'resource_owner' => ':resource_owner'])->setParameters(['guid' => $guid, 'provider' => $provider, 'resource_owner_id' => $resourceOwnerId, 'refresh_token' => $accessToken->getRefreshToken(), 'lastupdate' => date('Y-m-d H:i:s', time()), 'resource_owner' => json_encode($resourceOwner->toArray())]);
 }
Example #4
0
 /**
  * Constructor.
  *
  * @param string                 $guid
  * @param string                 $providerName
  * @param AccessToken            $accessToken
  * @param ResourceOwnerInterface $resourceOwner
  */
 public function __construct($guid, $providerName, AccessToken $accessToken, ResourceOwnerInterface $resourceOwner)
 {
     if (Uuid::isValid($guid) === false) {
         throw new \RuntimeException('Tried to create Transition object with an invalid GUID.');
     }
     $this->guid = $guid;
     $this->accessToken = $accessToken;
     $this->resourceOwner = $resourceOwner;
     $providerEntity = new Entity\Provider();
     $providerEntity->setProvider($providerName);
     $providerEntity->setRefreshToken($accessToken->getRefreshToken());
     $providerEntity->setResourceOwnerId($resourceOwner->getId());
     $providerEntity->setResourceOwner($resourceOwner);
     $this->providerEntity = $providerEntity;
 }
Example #5
0
 /**
  * @throws Exception
  * @param sring $method
  * @param string $path
  * @param array $options
  * @return ResponseInterface
  */
 public function call($method, $path, array $options = [])
 {
     $doRequest = function ($method, $path, $accessToken, $options) {
         $request = $this->provider->getAuthenticatedRequest($method, $this->provider->domain . "/{$path}", $accessToken, $options);
         return $this->provider->getHttpClient()->send($request);
     };
     try {
         $response = $doRequest($method, $path, $this->accessToken, $options);
     } catch (ClientException $e) {
         if (!$this->accessToken instanceof AccessToken || !$this->accessToken->hasExpired()) {
             throw new Exception($e->getMessage(), $e->getCode(), $e);
         }
         $newAccessToken = $this->provider->getAccessToken('refresh_token', ['refresh_token' => $this->accessToken->getRefreshToken()]);
         $response = $doRequest($method, $path, $newAccessToken, $options);
     }
     return $response;
 }
 /**
  * Find a token matching the given parameters, or create one if it doesn't exist
  *
  * @param string $provider
  * @param AccessToken $token
  * @return self
  */
 public static function createFromAccessToken($provider, AccessToken $token)
 {
     $data = ['Provider' => $provider, 'Token' => $token->getToken(), 'RefreshToken' => $token->getRefreshToken(), 'Expires' => $token->getExpires(), 'ResourceOwnerID' => $token->getResourceOwnerId()];
     $token = static::create()->update($data);
     return $token;
 }
Example #7
0
 public function refreshAccessToken(AccessToken $oldAccessToken)
 {
     $newAccessToken = $this->getAccessToken('refresh_token', ['refresh_token' => $oldAccessToken->getRefreshToken()]);
     //Add old resource owner id to new token (because resource owner id is not returned on token refresh)
     $newAccessToken = new AccessToken(['resource_owner_id' => $oldAccessToken->getResourceOwnerId()] + $newAccessToken->jsonSerialize());
     return $newAccessToken;
 }