Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Reddit.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.38 KiB


 001  <?php
 002   
 003  namespace OAuth\OAuth2\Service;
 004   
 005  use OAuth\OAuth2\Token\StdOAuth2Token;
 006  use OAuth\Common\Http\Exception\TokenResponseException;
 007  use OAuth\Common\Http\Uri\Uri;
 008  use OAuth\Common\Consumer\CredentialsInterface;
 009  use OAuth\Common\Http\Client\ClientInterface;
 010  use OAuth\Common\Storage\TokenStorageInterface;
 011  use OAuth\Common\Http\Uri\UriInterface;
 012   
 013  class Reddit extends AbstractService
 014  {
 015      /**
 016       * Defined scopes
 017       *
 018       * @link 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 = array(),
 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']);
 098          unset($data['expires_in']);
 099   
 100          $token->setExtraParams($data);
 101   
 102          return $token;
 103      }
 104   
 105      /**
 106       * {@inheritdoc}
 107       */
 108      protected function getExtraOAuthHeaders()
 109      {
 110          // Reddit uses a Basic OAuth header
 111          return array('Authorization' => 'Basic ' .
 112              base64_encode($this->credentials->getConsumerId() . ':' . $this->credentials->getConsumerSecret()));
 113      }
 114  }
 115