예제 #1
0
 /**
  * Refreshes an OAuth2 access token.
  *
  * @param TokenInterface $token
  *
  * @return TokenInterface $token
  *
  * @throws MissingRefreshTokenException
  */
 public function refreshAccessToken(TokenInterface $token)
 {
     $refreshToken = $token->getRefreshToken();
     if (empty($refreshToken)) {
         throw new MissingRefreshTokenException();
     }
     $parameters = array('grant_type' => 'refresh_token', 'type' => 'web_server', 'client_id' => $this->credentials->getConsumerId(), 'client_secret' => $this->credentials->getConsumerSecret(), 'refresh_token' => $refreshToken);
     $responseBody = $this->httpClient->retrieveResponse($this->getAccessTokenEndpoint(), $parameters, $this->getExtraOAuthHeaders());
     $token = $this->parseAccessTokenResponse($responseBody);
     $this->storage->storeAccessToken($this->service(), $token);
     return $token;
 }
예제 #2
0
 /**
  * @param TokenInterface $token
  * @return bool
  */
 protected function checkTokenLifetime($token)
 {
     // assume that we have at least a minute to execute a queries.
     return $token->getEndOfLife() - 60 > time() || $token->getEndOfLife() === TokenInterface::EOL_NEVER_EXPIRES;
 }
예제 #3
0
 public function json_encode_token(TokenInterface $token)
 {
     $members = array('accessToken' => $token->getAccessToken(), 'endOfLife' => $token->getEndOfLife(), 'extraParams' => $token->getExtraParams(), 'refreshToken' => $token->getRefreshToken(), 'token_class' => get_class($token));
     // Handle additional data needed for OAuth1 tokens
     if ($token instanceof StdOAuth1Token) {
         $members['requestToken'] = $token->getRequestToken();
         $members['requestTokenSecret'] = $token->getRequestTokenSecret();
         $members['accessTokenSecret'] = $token->getAccessTokenSecret();
     }
     return json_encode($members);
 }
 /**
  * Request access token from Facebook and return a LoginRequest object for logging into our app
  *
  * @param  Oauth2Service\Facebook $facebook
  * @param  TokenInterface         $token
  * @return LoginRequest
  */
 protected function facebook(Oauth2Service\Facebook $facebook, TokenInterface $token)
 {
     $user = json_decode($facebook->request('/me'), true);
     $loginRequest = new LoginRequest('facebook', $user['id'], $token->getAccessToken(), $token->getEndOfLife() > 0 ? $token->getEndOfLife() : 0, $token->getRefreshToken(), [$user['email']]);
     return $loginRequest;
 }