/**
  * Create an authentication cookie.
  *
  * @param string      $path
  * @param AccessToken $accessToken
  *
  * @return \Symfony\Component\HttpFoundation\Cookie
  */
 public static function create($path, AccessToken $accessToken)
 {
     if (!($expire = $accessToken->getExpires())) {
         $expire = time() + 3600;
     }
     return new CookieBase(TokenManager::TOKEN_COOKIE_NAME, $accessToken->getToken(), $expire, $path);
 }
Exemplo n.º 2
0
 /**
  * @return int Expiration time of token (unix epoch)
  * @throws FitbitTokenMissingException
  */
 public function getTokenExpiry()
 {
     if (empty($this->access_token)) {
         throw new FitbitTokenMissingException();
     }
     return $this->access_token->getExpires();
 }
Exemplo n.º 3
0
 /**
  * Returns the Guzzle client
  *
  * @return Client
  * @throws LoginException
  */
 public function getClient()
 {
     if ($this->_client === null) {
         if (!$this->_accessToken) {
             throw new LoginException('The storage did not return a token. Please check your storage provider settings or sign in again');
         }
         if ($this->_accessToken->getExpires() !== null && $this->_accessToken->hasExpired()) {
             throw new LoginException('The current auth token has expired');
         }
         $this->_client = new Client(['base_uri' => App::ENDPOINT . App::VERSION . '/', 'allow_redirects' => false, 'headers' => ['User-Agent' => 'ApiClient-php/' . self::CLIENT_VERSION, 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->_accessToken->getToken()]]);
     }
     return $this->_client;
 }
 /**
  * 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;
 }
 /**
  * Returns the Expires timestamp of the Access Token
  *
  * @return int
  */
 public function getExpires()
 {
     return $this->accessToken->getExpires();
 }
Exemplo n.º 6
0
 /**
  * Ensure an access token always has a valid expiry field.
  *
  * @param AccessToken $accessToken
  *
  * @return AccessToken
  */
 private function setAccessTokenExpires(AccessToken $accessToken)
 {
     if ($accessToken->getExpires() !== null) {
         return $accessToken;
     }
     // Set the expiry to one hour in the future
     $tokenData = json_decode(json_encode($accessToken), true);
     $tokenData['expiry'] = 3600;
     return new AccessToken($tokenData);
 }