OAuthOAuth2ServicePocket

The Gravity Forms Salesforce Add-On OAuth OAuth2 Service Pocket class.

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Pocket.php  
  1. class Pocket 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. if ($baseApiUri === null) { 
  11. $this->baseApiUri = new Uri('https://getpocket.com/v3/'); 
  12.  
  13. public function getRequestTokenEndpoint() 
  14. return new Uri('https://getpocket.com/v3/oauth/request'); 
  15.  
  16. public function getAuthorizationEndpoint() 
  17. return new Uri('https://getpocket.com/auth/authorize'); 
  18.  
  19. public function getAccessTokenEndpoint() 
  20. return new Uri('https://getpocket.com/v3/oauth/authorize'); 
  21.  
  22. public function getAuthorizationUri(array $additionalParameters = array()) 
  23. $parameters = array_merge( 
  24. $additionalParameters,  
  25. array( 
  26. 'redirect_uri' => $this->credentials->getCallbackUrl(),  
  27. ); 
  28.  
  29. // Build the url 
  30. $url = clone $this->getAuthorizationEndpoint(); 
  31. foreach ($parameters as $key => $val) { 
  32. $url->addToQuery($key, $val); 
  33.  
  34. return $url; 
  35.  
  36. public function requestRequestToken() 
  37. $responseBody = $this->httpClient->retrieveResponse( 
  38. $this->getRequestTokenEndpoint(),  
  39. array( 
  40. 'consumer_key' => $this->credentials->getConsumerId(),  
  41. 'redirect_uri' => $this->credentials->getCallbackUrl(),  
  42. ); 
  43.  
  44. $code = $this->parseRequestTokenResponse($responseBody); 
  45.  
  46. return $code; 
  47.  
  48. protected function parseRequestTokenResponse($responseBody) 
  49. parse_str($responseBody, $data); 
  50.  
  51. if (null === $data || !is_array($data)) { 
  52. throw new TokenResponseException('Unable to parse response.'); 
  53. } elseif (!isset($data['code'])) { 
  54. throw new TokenResponseException('Error in retrieving code.'); 
  55. return $data['code']; 
  56.  
  57. public function requestAccessToken($code) 
  58. $bodyParams = array( 
  59. 'consumer_key' => $this->credentials->getConsumerId(),  
  60. 'code' => $code,  
  61. ); 
  62.  
  63. $responseBody = $this->httpClient->retrieveResponse( 
  64. $this->getAccessTokenEndpoint(),  
  65. $bodyParams,  
  66. $this->getExtraOAuthHeaders() 
  67. ); 
  68. $token = $this->parseAccessTokenResponse($responseBody); 
  69. $this->storage->storeAccessToken($this->service(), $token); 
  70.  
  71. return $token; 
  72.  
  73. protected function parseAccessTokenResponse($responseBody) 
  74. parse_str($responseBody, $data); 
  75.  
  76. if ($data === null || !is_array($data)) { 
  77. throw new TokenResponseException('Unable to parse response.'); 
  78. } elseif (isset($data['error'])) { 
  79. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  80.  
  81. $token = new StdOAuth2Token(); 
  82. #$token->setRequestToken($data['access_token']); 
  83. $token->setAccessToken($data['access_token']); 
  84. $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES); 
  85. unset($data['access_token']); 
  86. $token->setExtraParams($data); 
  87.  
  88. return $token;