Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Reddit.php
001 <?php
002
003 namespace OAuth\OAuth2\Service;
004
005 use OAuth\Common\Consumer\CredentialsInterface;
006 use OAuth\Common\Http\Client\ClientInterface;
007 use OAuth\Common\Http\Exception\TokenResponseException;
008 use OAuth\Common\Http\Uri\Uri;
009 use OAuth\Common\Http\Uri\UriInterface;
010 use OAuth\Common\Storage\TokenStorageInterface;
011 use OAuth\OAuth2\Token\StdOAuth2Token;
012
013 class Reddit extends AbstractService
014 {
015 /**
016 * Defined scopes.
017 *
018 * @see http://www.reddit.com/dev/api/oauth
019 */
020 // User scopes
021 const SCOPE_EDIT = 'edit';
022 const SCOPE_HISTORY = 'history';
023 const SCOPE_IDENTITY = 'identity';
024 const SCOPE_MYSUBREDDITS = 'mysubreddits';
025 const SCOPE_PRIVATEMESSAGES = 'privatemessages';
026 const SCOPE_READ = 'read';
027 const SCOPE_SAVE = 'save';
028 const SCOPE_SUBMIT = 'submit';
029 const SCOPE_SUBSCRIBE = 'subscribe';
030 const SCOPE_VOTE = 'vote';
031 // Mod Scopes
032 const SCOPE_MODCONFIG = 'modconfig';
033 const SCOPE_MODFLAIR = 'modflair';
034 const SCOPE_MODLOG = 'modlog';
035 const SCOPE_MODPOST = 'modpost';
036
037 public function __construct(
038 CredentialsInterface $credentials,
039 ClientInterface $httpClient,
040 TokenStorageInterface $storage,
041 $scopes = [],
042 ?UriInterface $baseApiUri = null
043 ) {
044 parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true);
045
046 if (null === $baseApiUri) {
047 $this->baseApiUri = new Uri('https://oauth.reddit.com');
048 }
049 }
050
051 /**
052 * {@inheritdoc}
053 */
054 public function getAuthorizationEndpoint()
055 {
056 return new Uri('https://ssl.reddit.com/api/v1/authorize');
057 }
058
059 /**
060 * {@inheritdoc}
061 */
062 public function getAccessTokenEndpoint()
063 {
064 return new Uri('https://ssl.reddit.com/api/v1/access_token');
065 }
066
067 /**
068 * {@inheritdoc}
069 */
070 protected function getAuthorizationMethod()
071 {
072 return static::AUTHORIZATION_METHOD_HEADER_BEARER;
073 }
074
075 /**
076 * {@inheritdoc}
077 */
078 protected function parseAccessTokenResponse($responseBody)
079 {
080 $data = json_decode($responseBody, true);
081
082 if (null === $data || !is_array($data)) {
083 throw new TokenResponseException('Unable to parse response.');
084 } elseif (isset($data['error'])) {
085 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
086 }
087
088 $token = new StdOAuth2Token();
089 $token->setAccessToken($data['access_token']);
090 $token->setLifeTime($data['expires_in']);
091
092 if (isset($data['refresh_token'])) {
093 $token->setRefreshToken($data['refresh_token']);
094 unset($data['refresh_token']);
095 }
096
097 unset($data['access_token'], $data['expires_in']);
098
099 $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 }
114