Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function refreshAccessToken(TokenInterface $token)
 {
     $extraParams = $token->getExtraParams();
     $bodyParams = array('oauth_session_handle' => $extraParams['oauth_session_handle']);
     $authorizationHeader = array('Authorization' => $this->buildAuthorizationHeaderForAPIRequest('POST', $this->getAccessTokenEndpoint(), $this->storage->retrieveAccessToken($this->service()), $bodyParams));
     $headers = array_merge($authorizationHeader, $this->getExtraOAuthHeaders(), array());
     $responseBody = $this->httpClient->retrieveResponse($this->getAccessTokenEndpoint(), $bodyParams, $headers);
     $token = $this->parseAccessTokenResponse($responseBody);
     $this->storage->storeAccessToken($this->service(), $token);
     return $token;
 }
 protected function buildAuthorizationHeaderForAPIRequest($method, UriInterface $uri, TokenInterface $token, $bodyParams = null)
 {
     $this->signature->setTokenSecret($token->getAccessTokenSecret());
     $parameters = $this->getBasicAuthorizationHeaderInfo();
     if (isset($parameters['oauth_callback'])) {
         unset($parameters['oauth_callback']);
     }
     $parameters = array_merge($parameters, ['oauth_token' => $token->getAccessToken()]);
     $parameters = array_merge($parameters, $bodyParams);
     $parameters['oauth_signature'] = $this->signature->getSignature($uri, $parameters, $method);
     $authorizationHeader = 'OAuth ';
     $delimiter = '';
     foreach ($parameters as $key => $value) {
         $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"';
         $delimiter = ', ';
     }
     return $authorizationHeader;
 }
Exemplo n.º 3
0
 /**
  * Validates a Test REST api call access using oauth access token
  *
  * @param TokenInterface $token The access token.
  * @param string $method HTTP method.
  * @return array
  * @throws TokenResponseException
  */
 public function validateAccessToken($token, $method = 'GET')
 {
     //Need to add Accept header else Magento errors out with 503
     $extraAuthenticationHeaders = ['Accept' => 'application/json'];
     $this->signature->setTokenSecret($token->getAccessTokenSecret());
     $authorizationHeader = ['Authorization' => $this->buildAuthorizationHeaderForAPIRequest($method, $this->getTestApiEndpoint(), $token, [])];
     $headers = array_merge($authorizationHeader, $extraAuthenticationHeaders);
     $responseBody = $this->httpClient->retrieveResponse($this->getTestApiEndpoint(), [], $headers, $method);
     return json_decode($responseBody);
 }
Exemplo n.º 4
0
 /**
  * 
  * @param type $method
  * @param UriInterface $uri
  * @param \OAuth\OAuth1\Token\TokenInterface $token
  * @param type $bodyParams
  * @return string
  */
 protected function buildAuthorizationHeaderForAPIRequest($method, UriInterface $uri, \OAuth\OAuth1\Token\TokenInterface $token, $bodyParams = null)
 {
     $this->signature->setTokenSecret($token->getAccessTokenSecret());
     $authParameters = $this->getBasicAuthorizationHeaderInfo();
     if (isset($authParameters['oauth_callback'])) {
         unset($authParameters['oauth_callback']);
     }
     $authParameters = array_merge($authParameters, array('oauth_token' => $token->getAccessToken()));
     $authParameters = is_array($bodyParams) ? array_merge($authParameters, $bodyParams) : $authParameters;
     //In base class here is because $bodyParams array is never merged with $authParameters
     $authParameters['oauth_signature'] = $this->signature->getSignature($uri, $authParameters, $method);
     if (isset($bodyParams['oauth_session_handle'])) {
         $authParameters['oauth_session_handle'] = $bodyParams['oauth_session_handle'];
         unset($bodyParams['oauth_session_handle']);
     }
     $authorizationHeader = 'OAuth ';
     $delimiter = '';
     foreach ($authParameters as $key => $value) {
         $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"';
         $delimiter = ', ';
     }
     return $authorizationHeader;
 }