OAuthOAuth2ServiceDropbox

Dropbox service.

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Dropbox.php  
  1. class Dropbox 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); 
  10.  
  11. if (null === $baseApiUri) { 
  12. $this->baseApiUri = new Uri('https://api.dropbox.com/1/'); 
  13.  
  14. /** 
  15. * {@inheritdoc} 
  16. */ 
  17. public function getAuthorizationUri(array $additionalParameters = array()) 
  18. $parameters = array_merge( 
  19. $additionalParameters,  
  20. array( 
  21. 'client_id' => $this->credentials->getConsumerId(),  
  22. 'redirect_uri' => $this->credentials->getCallbackUrl(),  
  23. 'response_type' => 'code',  
  24. ); 
  25.  
  26. $parameters['scope'] = implode(' ', $this->scopes); 
  27.  
  28. // Build the url 
  29. $url = clone $this->getAuthorizationEndpoint(); 
  30. foreach ($parameters as $key => $val) { 
  31. $url->addToQuery($key, $val); 
  32.  
  33. return $url; 
  34.  
  35. /** 
  36. * {@inheritdoc} 
  37. */ 
  38. public function getAuthorizationEndpoint() 
  39. return new Uri('https://www.dropbox.com/1/oauth2/authorize'); 
  40.  
  41. /** 
  42. * {@inheritdoc} 
  43. */ 
  44. public function getAccessTokenEndpoint() 
  45. return new Uri('https://api.dropbox.com/1/oauth2/token'); 
  46.  
  47. /** 
  48. * {@inheritdoc} 
  49. */ 
  50. protected function getAuthorizationMethod() 
  51. return static::AUTHORIZATION_METHOD_QUERY_STRING; 
  52.  
  53. /** 
  54. * {@inheritdoc} 
  55. */ 
  56. protected function parseAccessTokenResponse($responseBody) 
  57. $data = json_decode($responseBody, true); 
  58.  
  59. if (null === $data || !is_array($data)) { 
  60. throw new TokenResponseException('Unable to parse response.'); 
  61. } elseif (isset($data['error'])) { 
  62. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  63.  
  64. $token = new StdOAuth2Token(); 
  65. $token->setAccessToken($data['access_token']); 
  66.  
  67. if (isset($data['refresh_token'])) { 
  68. $token->setRefreshToken($data['refresh_token']); 
  69. unset($data['refresh_token']); 
  70.  
  71. unset($data['access_token']); 
  72.  
  73. $token->setExtraParams($data); 
  74.  
  75. return $token;