protected function _parseToken($responseBody)
 {
     $data = $this->_parseResponseBody($responseBody);
     $token = new StdOAuth1Token();
     $token->setRequestToken($data['oauth_token']);
     $token->setRequestTokenSecret($data['oauth_token_secret']);
     $token->setAccessToken($data['oauth_token']);
     $token->setAccessTokenSecret($data['oauth_token_secret']);
     $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
     unset($data['oauth_token'], $data['oauth_token_secret']);
     $token->setExtraParams($data);
     return $token;
 }
示例#2
0
 public function __construct(CredentialsInterface $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, SignatureInterface $signature, UriInterface $baseApiUri = null)
 {
     //This is a bit of a hack; but Not really sure what else todo.
     $signature = new SignatureRsaSha1($credentials);
     parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
     if (null === $baseApiUri) {
         $this->baseApiUri = new Uri('https://api.xero.com/api.xro/2.0/');
     }
     //Hack like a shit c**t.
     $a = new \OAuth\OAuth1\Token\StdOAuth1Token();
     $a->setAccessToken($this->credentials->getConsumerId());
     $a->setAccessTokenSecret($this->credentials->getConsumerSecret());
     $this->storage->storeAccessToken($this->service(), $a);
 }
示例#3
0
文件: Yahoo.php 项目: nukeplus/nuke
 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     parse_str($responseBody, $data);
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth1Token();
     $token->setRequestToken($data['oauth_token']);
     $token->setRequestTokenSecret($data['oauth_token_secret']);
     $token->setAccessToken($data['oauth_token']);
     $token->setAccessTokenSecret($data['oauth_token_secret']);
     $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
     unset($data['oauth_token'], $data['oauth_token_secret']);
     $token->setExtraParams($data);
     return $token;
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($sResponseBody)
 {
     $aData = array();
     parse_str($sResponseBody, $aData);
     if ($aData === null || !is_array($aData)) {
         throw new TokenResponseException('Unable to parse response.');
     } else {
         if (isset($aData['oauth_err_code']) && isset($aData['oauth_err_message'])) {
             throw new TokenResponseException('Error in retrieving token: "' . $aData['oauth_err_message'] . '"');
         }
     }
     $oToken = new StdOAuth1Token();
     $oToken->setRequestToken($aData['oauth_token']);
     $oToken->setRequestTokenSecret($aData['oauth_token_secret']);
     $oToken->setAccessToken($aData['oauth_token']);
     $oToken->setAccessTokenSecret($aData['oauth_token_secret']);
     $oToken->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
     unset($aData['oauth_token'], $aData['oauth_token_secret']);
     $oToken->setExtraParams($aData);
     return $oToken;
 }
示例#5
0
 public function refreshAccessToken()
 {
     $access_token = $this->access_token;
     $service = Facades\Social::service($this->provider);
     if (2 === Facades\Social::oauthSpec($this->provider)) {
         $token = new StdOAuth2Token();
         $token->setAccessToken(array_get($access_token, 'token'));
         $token->setRefreshToken(array_get($access_token, 'refresh_token'));
     } else {
         $token = new StdOAuth1Token();
         $token->setAccessToken(array_get($access_token, 'token'));
         $token->setAccessTokenSecret(array_get($access_token, 'secret'));
         $token->setRefreshToken(array_get($access_token, 'refresh_token'));
     }
     $service->getStorage()->storeAccessToken(ucfirst($this->provider), $token);
     try {
         $new_token = $service->refreshAccessToken($token);
     } catch (\Exception $e) {
         return false;
     }
     if (!$new_token->getAccessToken()) {
         return false;
     }
     $access_token['token'] = $new_token->getAccessToken();
     if ($new_token->getEndOfLife()) {
         $access_token['end_of_life'] = $new_token->getEndOfLife();
     }
     if ($new_token->getExtraParams()) {
         $access_token['extra_params'] = $new_token->getExtraParams();
     }
     if (2 !== Facades\Social::oauthSpec($this->provider) && $new_token->getAccessTokenSecret()) {
         $access_token['secret'] = $new_token->getAccessTokenSecret();
     }
     $this->access_token = $access_token;
     $this->save();
     return true;
 }
 /**
  * Builds the oAuth authorization header for an authenticated API request
  *
  * @param UriInterface $uri the uri the request is headed
  * @param \OAuth\OAuth1\Token\TokenInterface $token
  * @param string $tokenSecret used to verify the passed token
  * @param array $bodyParams
  * @param string $method HTTP method to use
  * @return array
  */
 public function buildOauthAuthorizationHeader($uri, $token, $tokenSecret, $bodyParams, $method = 'GET')
 {
     $uri = new Uri($uri);
     $tokenObj = new StdOAuth1Token();
     $tokenObj->setAccessToken($token);
     $tokenObj->setAccessTokenSecret($tokenSecret);
     $tokenObj->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
     return ['Authorization: ' . $this->buildAuthorizationHeaderForAPIRequest($method, $uri, $tokenObj, $bodyParams)];
 }
示例#7
0
 /**
  * @param string|array $responseBody
  * @return StdOAuth1Token
  * @throws TokenResponseException
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     if (!is_array($responseBody)) {
         parse_str($responseBody, $data);
         if (!isset($data) || !is_array($data)) {
             throw new TokenResponseException('Unable to parse response.');
         }
     } else {
         $data = $responseBody;
     }
     $error = $this->service->getAccessTokenResponseError($data);
     if (isset($error)) {
         throw new TokenResponseException('Error in retrieving token: "' . $error . '"');
     }
     $token = new StdOAuth1Token();
     $names = $this->service->getAccessTokenArgumentNames();
     $token->setRequestToken($data[$names['oauth_token']]);
     $token->setRequestTokenSecret($data[$names['oauth_token_secret']]);
     $token->setAccessToken($data[$names['oauth_token']]);
     $token->setAccessTokenSecret($data[$names['oauth_token_secret']]);
     unset($data[$names['oauth_token']], $data[$names['oauth_token_secret']]);
     if (isset($data[$names['oauth_expires_in']])) {
         $token->setLifeTime($data[$names['oauth_expires_in']]);
         unset($data[$names['oauth_expires_in']]);
     } else {
         $token->setLifetime($this->service->getTokenDefaultLifetime());
     }
     $token->setExtraParams($data);
     return $token;
 }
示例#8
0
 protected function parseAccessTokenResponse($responseBody)
 {
     $token = new StdOAuth1Token();
     $token->setAccessToken($responseBody);
     return $token;
 }
示例#9
0
 /**
  * Will use your own token (you may have stored in DB)
  *
  * @param $accessToken
  * @param $secret
  */
 public function setAccessToken($accessToken, $secret)
 {
     $this->init();
     $token = new StdOAuth1Token();
     $token->setAccessToken($accessToken);
     $token->setAccessTokenSecret($secret);
     $this->storage->storeAccessToken($this->getServiceName(), $token);
 }