[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace OAuth\OAuth2\Service; 4 5 use OAuth\Common\Consumer\CredentialsInterface; 6 use OAuth\Common\Http\Client\ClientInterface; 7 use OAuth\Common\Http\Exception\TokenResponseException; 8 use OAuth\Common\Http\Uri\Uri; 9 use OAuth\Common\Http\Uri\UriInterface; 10 use OAuth\Common\Storage\TokenStorageInterface; 11 use OAuth\OAuth2\Token\StdOAuth2Token; 12 13 class Reddit extends AbstractService 14 { 15 /** 16 * Defined scopes. 17 * 18 * @see http://www.reddit.com/dev/api/oauth 19 */ 20 // User scopes 21 const SCOPE_EDIT = 'edit'; 22 const SCOPE_HISTORY = 'history'; 23 const SCOPE_IDENTITY = 'identity'; 24 const SCOPE_MYSUBREDDITS = 'mysubreddits'; 25 const SCOPE_PRIVATEMESSAGES = 'privatemessages'; 26 const SCOPE_READ = 'read'; 27 const SCOPE_SAVE = 'save'; 28 const SCOPE_SUBMIT = 'submit'; 29 const SCOPE_SUBSCRIBE = 'subscribe'; 30 const SCOPE_VOTE = 'vote'; 31 // Mod Scopes 32 const SCOPE_MODCONFIG = 'modconfig'; 33 const SCOPE_MODFLAIR = 'modflair'; 34 const SCOPE_MODLOG = 'modlog'; 35 const SCOPE_MODPOST = 'modpost'; 36 37 public function __construct( 38 CredentialsInterface $credentials, 39 ClientInterface $httpClient, 40 TokenStorageInterface $storage, 41 $scopes = [], 42 ?UriInterface $baseApiUri = null 43 ) { 44 parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true); 45 46 if (null === $baseApiUri) { 47 $this->baseApiUri = new Uri('https://oauth.reddit.com'); 48 } 49 } 50 51 /** 52 * {@inheritdoc} 53 */ 54 public function getAuthorizationEndpoint() 55 { 56 return new Uri('https://ssl.reddit.com/api/v1/authorize'); 57 } 58 59 /** 60 * {@inheritdoc} 61 */ 62 public function getAccessTokenEndpoint() 63 { 64 return new Uri('https://ssl.reddit.com/api/v1/access_token'); 65 } 66 67 /** 68 * {@inheritdoc} 69 */ 70 protected function getAuthorizationMethod() 71 { 72 return static::AUTHORIZATION_METHOD_HEADER_BEARER; 73 } 74 75 /** 76 * {@inheritdoc} 77 */ 78 protected function parseAccessTokenResponse($responseBody) 79 { 80 $data = json_decode($responseBody, true); 81 82 if (null === $data || !is_array($data)) { 83 throw new TokenResponseException('Unable to parse response.'); 84 } elseif (isset($data['error'])) { 85 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 86 } 87 88 $token = new StdOAuth2Token(); 89 $token->setAccessToken($data['access_token']); 90 $token->setLifeTime($data['expires_in']); 91 92 if (isset($data['refresh_token'])) { 93 $token->setRefreshToken($data['refresh_token']); 94 unset($data['refresh_token']); 95 } 96 97 unset($data['access_token'], $data['expires_in']); 98 99 $token->setExtraParams($data); 100 101 return $token; 102 } 103 104 /** 105 * {@inheritdoc} 106 */ 107 protected function getExtraOAuthHeaders() 108 { 109 // Reddit uses a Basic OAuth header 110 return ['Authorization' => 'Basic ' . 111 base64_encode($this->credentials->getConsumerId() . ':' . $this->credentials->getConsumerSecret()), ]; 112 } 113 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |