OAuthOAuth2ServiceHeroku

Heroku service.

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Heroku.php  
  1. class Heroku extends AbstractService 
  2. /** 
  3. * Defined scopes 
  4. * @link https://devcenter.heroku.com/articles/oauth#scopes 
  5. */ 
  6. const SCOPE_GLOBAL = 'global'; 
  7. const SCOPE_IDENTITY = 'identity'; 
  8. const SCOPE_READ = 'read'; 
  9. const SCOPE_WRITE = 'write'; 
  10. const SCOPE_READ_PROTECTED = 'read-protected'; 
  11. const SCOPE_WRITE_PROTECTED = 'write-protected'; 
  12.  
  13. /** 
  14. * {@inheritdoc} 
  15. */ 
  16. public function __construct( 
  17. CredentialsInterface $credentials,  
  18. ClientInterface $httpClient,  
  19. TokenStorageInterface $storage,  
  20. $scopes = array(),  
  21. UriInterface $baseApiUri = null 
  22. ) { 
  23. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); 
  24.  
  25. if (null === $baseApiUri) { 
  26. $this->baseApiUri = new Uri('https://api.heroku.com/'); 
  27.  
  28. /** 
  29. * {@inheritdoc} 
  30. */ 
  31. public function getAuthorizationEndpoint() 
  32. return new Uri('https://id.heroku.com/oauth/authorize'); 
  33.  
  34. /** 
  35. * {@inheritdoc} 
  36. */ 
  37. public function getAccessTokenEndpoint() 
  38. return new Uri('https://id.heroku.com/oauth/token'); 
  39.  
  40. /** 
  41. * {@inheritdoc} 
  42. */ 
  43. protected function getAuthorizationMethod() 
  44. return static::AUTHORIZATION_METHOD_HEADER_BEARER; 
  45.  
  46. /** 
  47. * {@inheritdoc} 
  48. */ 
  49. protected function parseAccessTokenResponse($responseBody) 
  50. $data = json_decode($responseBody, true); 
  51.  
  52. if (null === $data || !is_array($data)) { 
  53. throw new TokenResponseException('Unable to parse response.'); 
  54. } elseif (isset($data['error_description']) || isset($data['error'])) { 
  55. throw new TokenResponseException( 
  56. sprintf( 
  57. 'Error in retrieving token: "%s"',  
  58. isset($data['error_description']) ? $data['error_description'] : $data['error'] 
  59. ); 
  60.  
  61. $token = new StdOAuth2Token(); 
  62. $token->setAccessToken($data['access_token']); 
  63. $token->setLifeTime($data['expires_in']); 
  64.  
  65. if (isset($data['refresh_token'])) { 
  66. $token->setRefreshToken($data['refresh_token']); 
  67. unset($data['refresh_token']); 
  68.  
  69. unset($data['access_token']); 
  70. unset($data['expires_in']); 
  71.  
  72. $token->setExtraParams($data); 
  73.  
  74. return $token; 
  75.  
  76. /** 
  77. * {@inheritdoc} 
  78. */ 
  79. protected function getExtraOAuthHeaders() 
  80. return array('Accept' => 'application/vnd.heroku+json; version=3'); 
  81.  
  82. /** 
  83. * {@inheritdoc} 
  84. */ 
  85. protected function getExtraApiHeaders() 
  86. return array('Accept' => 'application/vnd.heroku+json; version=3', 'Content-Type' => 'application/json');