OAuthOAuth2ServiceReddit

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

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Reddit.php  
  1. class Reddit extends AbstractService 
  2. /** 
  3. * Defined scopes 
  4. * @link http://www.reddit.com/dev/api/oauth 
  5. */ 
  6. // User scopes 
  7. const SCOPE_EDIT = 'edit'; 
  8. const SCOPE_HISTORY = 'history'; 
  9. const SCOPE_IDENTITY = 'identity'; 
  10. const SCOPE_MYSUBREDDITS = 'mysubreddits'; 
  11. const SCOPE_PRIVATEMESSAGES = 'privatemessages'; 
  12. const SCOPE_READ = 'read'; 
  13. const SCOPE_SAVE = 'save'; 
  14. const SCOPE_SUBMIT = 'submit'; 
  15. const SCOPE_SUBSCRIBE = 'subscribe'; 
  16. const SCOPE_VOTE = 'vote'; 
  17. // Mod Scopes 
  18. const SCOPE_MODCONFIG = 'modconfig'; 
  19. const SCOPE_MODFLAIR = 'modflair'; 
  20. const SCOPE_MODLOG = 'modlog'; 
  21. const SCOPE_MODPOST = 'modpost'; 
  22.  
  23. public function __construct( 
  24. CredentialsInterface $credentials,  
  25. ClientInterface $httpClient,  
  26. TokenStorageInterface $storage,  
  27. $scopes = array(),  
  28. UriInterface $baseApiUri = null 
  29. ) { 
  30. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true); 
  31.  
  32. if (null === $baseApiUri) { 
  33. $this->baseApiUri = new Uri('https://oauth.reddit.com'); 
  34.  
  35. /** 
  36. * {@inheritdoc} 
  37. */ 
  38. public function getAuthorizationEndpoint() 
  39. return new Uri('https://ssl.reddit.com/api/v1/authorize'); 
  40.  
  41. /** 
  42. * {@inheritdoc} 
  43. */ 
  44. public function getAccessTokenEndpoint() 
  45. return new Uri('https://ssl.reddit.com/api/v1/access_token'); 
  46.  
  47. /** 
  48. * {@inheritdoc} 
  49. */ 
  50. protected function getAuthorizationMethod() 
  51. return static::AUTHORIZATION_METHOD_HEADER_BEARER; 
  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. $token->setLifeTime($data['expires_in']); 
  67.  
  68. if (isset($data['refresh_token'])) { 
  69. $token->setRefreshToken($data['refresh_token']); 
  70. unset($data['refresh_token']); 
  71.  
  72. unset($data['access_token']); 
  73. unset($data['expires_in']); 
  74.  
  75. $token->setExtraParams($data); 
  76.  
  77. return $token; 
  78.  
  79. /** 
  80. * {@inheritdoc} 
  81. */ 
  82. protected function getExtraOAuthHeaders() 
  83. // Reddit uses a Basic OAuth header 
  84. return array('Authorization' => 'Basic ' . 
  85. base64_encode($this->credentials->getConsumerId() . ':' . $this->credentials->getConsumerSecret()));