OAuthOAuth2ServiceBox

Box service.

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Box.php  
  1. class Box extends AbstractService 
  2. public function __construct( 
  3. CredentialsInterface $credentials,  
  4. ClientInterface $httpClient,  
  5. TokenStorageInterface $storage,  
  6. $scopes = array(),  
  7. UriInterface $baseApiUri = null 
  8. ) { 
  9. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true); 
  10.  
  11. if (null === $baseApiUri) { 
  12. $this->baseApiUri = new Uri('https://api.box.com/2.0/'); 
  13.  
  14. /** 
  15. * {@inheritdoc} 
  16. */ 
  17. public function getAuthorizationEndpoint() 
  18. return new Uri('https://www.box.com/api/oauth2/authorize'); 
  19.  
  20. /** 
  21. * {@inheritdoc} 
  22. */ 
  23. public function getAccessTokenEndpoint() 
  24. return new Uri('https://www.box.com/api/oauth2/token'); 
  25.  
  26. /** 
  27. * {@inheritdoc} 
  28. */ 
  29. protected function getAuthorizationMethod() 
  30. return static::AUTHORIZATION_METHOD_HEADER_BEARER; 
  31.  
  32. /** 
  33. * {@inheritdoc} 
  34. */ 
  35. protected function parseAccessTokenResponse($responseBody) 
  36. $data = json_decode($responseBody, true); 
  37.  
  38. if (null === $data || !is_array($data)) { 
  39. throw new TokenResponseException('Unable to parse response.'); 
  40. } elseif (isset($data['error'])) { 
  41. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  42.  
  43. $token = new StdOAuth2Token(); 
  44. $token->setAccessToken($data['access_token']); 
  45. $token->setLifeTime($data['expires_in']); 
  46.  
  47. if (isset($data['refresh_token'])) { 
  48. $token->setRefreshToken($data['refresh_token']); 
  49. unset($data['refresh_token']); 
  50.  
  51. unset($data['access_token']); 
  52. unset($data['expires_in']); 
  53.  
  54. $token->setExtraParams($data); 
  55.  
  56. return $token;