示例#1
0
 /**
  * @param Response $response
  * @param ServiceProviderInterface $serviceProvider
  * @return RequestTokenInterface
  */
 public static function factory(Response $response, ServiceProviderInterface $serviceProvider)
 {
     $rawToken = ResponseParser::parse($response, $serviceProvider->getRequestTokenFormat());
     $tokenValue = empty($rawToken['oauth_token']) ? '' : $rawToken['oauth_token'];
     $tokenSecret = empty($rawToken['oauth_token_secret']) ? '' : $rawToken['oauth_token_secret'];
     //$callbackConfirmed = empty($rawToken['oauth_callback_confirmed']) ? false : true;
     //TODO callback confirm handle
     $token = new static($tokenValue, $tokenSecret);
     $token->setResponse($response);
     return $token;
 }
示例#2
0
 /**
  * @param Response $response
  * @param ServiceProviderInterface $serviceProvider
  * @param array $options
  * @return AccessToken
  */
 public static function factory(Response $response, ServiceProviderInterface $serviceProvider, array $options)
 {
     $rawToken = ResponseParser::parse($response, $serviceProvider->getAccessTokenFormat());
     $tokenValue = empty($rawToken['oauth_token']) ? '' : $rawToken['oauth_token'];
     $tokenSecret = empty($rawToken['oauth_token_secret']) ? '' : $rawToken['oauth_token_secret'];
     $token = new static(['consumer_key' => $options['consumer_key'], 'consumer_secret' => $options['consumer_secret'], 'token_value' => $tokenValue, 'token_secret' => $tokenSecret]);
     $token->setResponse($response);
     foreach ($rawToken as $key => $value) {
         $token->{$key} = $value;
     }
     return $token;
 }
示例#3
0
 /**
  * @param ServiceProviderInterface $serviceProvider
  * @param array $urlQuery
  * @param RequestToken $requestToken
  * @return AccessToken
  */
 public function getAccessToken(ServiceProviderInterface $serviceProvider, array $urlQuery = [], RequestToken $requestToken = null)
 {
     $urlQuery = $urlQuery ?: $_GET;
     $tokenValue = empty($urlQuery['oauth_token']) ? '' : $urlQuery['oauth_token'];
     $tokenVerify = empty($urlQuery['oauth_verifier']) ? '' : $urlQuery['oauth_verifier'];
     if (!$tokenValue || !$tokenVerify) {
         throw new InvalidArgumentException(sprintf('No oauth_token or oauth_verifier input'));
     }
     /** @var RequestToken $requestToken */
     $requestToken = $requestToken ?: $this->getStorage()->fetch(md5($tokenValue));
     if (!$requestToken) {
         throw new InvalidArgumentException(sprintf('No request token found in storage'));
     }
     if ($tokenValue != $requestToken->getTokenValue()) {
         throw new VerifyException(sprintf('Request token not match'));
     }
     $options = $this->options;
     $httpMethod = $serviceProvider->getAccessTokenMethod();
     $url = $serviceProvider->getAccessTokenUrl();
     $parameters = ['oauth_consumer_key' => $options['consumer_key'], 'oauth_signature_method' => $this->signatureMethod, 'oauth_timestamp' => (string) time(), 'oauth_nonce' => Text::generateRandomString(32), 'oauth_token' => $tokenValue, 'oauth_version' => '1.0', 'oauth_verifier' => $tokenVerify, 'oauth_callback' => $options['callback']];
     $baseString = Text::buildBaseString($httpMethod, $url, $parameters);
     $signatureClass = $this->getSignatureClass();
     $signature = (string) new $signatureClass($baseString, $options['consumer_secret'], $requestToken->getTokenSecret());
     $parameters['oauth_signature'] = $signature;
     $httpClient = self::getHttpClient();
     $httpClientOptions = ['headers' => ['X-EvaOAuth-Debug-BaseString' => $baseString, 'Authorization' => Text::buildHeaderString($parameters)], 'body' => ['oauth_verifier' => $tokenVerify]];
     $request = $httpClient->createRequest($httpMethod, $url, $httpClientOptions);
     try {
         $this->getEmitter()->emit('beforeGetAccessToken', new BeforeGetAccessToken($request, $serviceProvider, $this));
         /** @var Response $response */
         $response = $httpClient->send($request);
         return AccessToken::factory($response, $serviceProvider, $options);
     } catch (RequestException $e) {
         throw new \Eva\EvaOAuth\Exception\RequestException('Get access token failed', $e->getRequest(), $e->getResponse());
     }
 }