OAuthOAuth2ServiceAmazon

Amazon service.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Amazon.php  
  1. class Amazon extends AbstractService 
  2. /** 
  3. * Defined scopes 
  4. * @link https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide._TTH_.pdf 
  5. */ 
  6. const SCOPE_PROFILE = 'profile'; 
  7. const SCOPE_POSTAL_CODE = 'postal_code'; 
  8.  
  9. public function __construct( 
  10. CredentialsInterface $credentials,  
  11. ClientInterface $httpClient,  
  12. TokenStorageInterface $storage,  
  13. $scopes = array(),  
  14. UriInterface $baseApiUri = null 
  15. ) { 
  16. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); 
  17.  
  18. if (null === $baseApiUri) { 
  19. $this->baseApiUri = new Uri('https://api.amazon.com/'); 
  20.  
  21. /** 
  22. * {@inheritdoc} 
  23. */ 
  24. public function getAuthorizationEndpoint() 
  25. return new Uri('https://www.amazon.com/ap/oa'); 
  26.  
  27. /** 
  28. * {@inheritdoc} 
  29. */ 
  30. public function getAccessTokenEndpoint() 
  31. return new Uri('https://www.amazon.com/ap/oatoken'); 
  32.  
  33. /** 
  34. * {@inheritdoc} 
  35. */ 
  36. protected function getAuthorizationMethod() 
  37. return static::AUTHORIZATION_METHOD_HEADER_BEARER; 
  38.  
  39. /** 
  40. * {@inheritdoc} 
  41. */ 
  42. protected function parseAccessTokenResponse($responseBody) 
  43. $data = json_decode($responseBody, true); 
  44.  
  45. if (null === $data || !is_array($data)) { 
  46. throw new TokenResponseException('Unable to parse response.'); 
  47. } elseif (isset($data['error_description'])) { 
  48. throw new TokenResponseException('Error in retrieving token: "' . $data['error_description'] . '"'); 
  49. } elseif (isset($data['error'])) { 
  50. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  51.  
  52. $token = new StdOAuth2Token(); 
  53. $token->setAccessToken($data['access_token']); 
  54. $token->setLifeTime($data['expires_in']); 
  55.  
  56. if (isset($data['refresh_token'])) { 
  57. $token->setRefreshToken($data['refresh_token']); 
  58. unset($data['refresh_token']); 
  59.  
  60. unset($data['access_token']); 
  61. unset($data['expires_in']); 
  62.  
  63. $token->setExtraParams($data); 
  64.  
  65. return $token;