Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

Buffer.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 4.27 KiB


 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  /**
 014   * Buffer API.
 015   *
 016   * @author  Sumukh Sridhara <@sumukhsridhara>
 017   *
 018   * @see https://bufferapp.com/developers/api
 019   */
 020  class Buffer extends AbstractService
 021  {
 022      public function __construct(
 023          CredentialsInterface $credentials,
 024          ClientInterface $httpClient,
 025          TokenStorageInterface $storage,
 026          $scopes = [],
 027          ?UriInterface $baseApiUri = null
 028      ) {
 029          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
 030          if ($baseApiUri === null) {
 031              $this->baseApiUri = new Uri('https://api.bufferapp.com/1/');
 032          }
 033      }
 034   
 035      /**
 036       * {@inheritdoc}
 037       */
 038      public function getAuthorizationEndpoint()
 039      {
 040          return new Uri('https://bufferapp.com/oauth2/authorize');
 041      }
 042   
 043      /**
 044       * {@inheritdoc}
 045       */
 046      public function getAccessTokenEndpoint()
 047      {
 048          return new Uri('https://api.bufferapp.com/1/oauth2/token.json');
 049      }
 050   
 051      /**
 052       * {@inheritdoc}
 053       */
 054      protected function getAuthorizationMethod()
 055      {
 056          return static::AUTHORIZATION_METHOD_QUERY_STRING;
 057      }
 058   
 059      /**
 060       * {@inheritdoc}
 061       */
 062      public function getAuthorizationUri(array $additionalParameters = [])
 063      {
 064          $parameters = array_merge(
 065              $additionalParameters,
 066              [
 067                  'client_id' => $this->credentials->getConsumerId(),
 068                  'redirect_uri' => $this->credentials->getCallbackUrl(),
 069                  'response_type' => 'code',
 070              ]
 071          );
 072   
 073          // Build the url
 074          $url = clone $this->getAuthorizationEndpoint();
 075          foreach ($parameters as $key => $val) {
 076              $url->addToQuery($key, $val);
 077          }
 078   
 079          return $url;
 080      }
 081   
 082      /**
 083       * {@inheritdoc}
 084       */
 085      public function requestRequestToken()
 086      {
 087          $responseBody = $this->httpClient->retrieveResponse(
 088              $this->getRequestTokenEndpoint(),
 089              [
 090                  'client_key' => $this->credentials->getConsumerId(),
 091                  'redirect_uri' => $this->credentials->getCallbackUrl(),
 092                  'response_type' => 'code',
 093              ]
 094          );
 095   
 096          $code = $this->parseRequestTokenResponse($responseBody);
 097   
 098          return $code;
 099      }
 100   
 101      protected function parseRequestTokenResponse($responseBody)
 102      {
 103          parse_str($responseBody, $data);
 104   
 105          if (null === $data || !is_array($data)) {
 106              throw new TokenResponseException('Unable to parse response.');
 107          } elseif (!isset($data['code'])) {
 108              throw new TokenResponseException('Error in retrieving code.');
 109          }
 110   
 111          return $data['code'];
 112      }
 113   
 114      public function requestAccessToken($code, $state = null)
 115      {
 116          $bodyParams = [
 117              'client_id' => $this->credentials->getConsumerId(),
 118              'client_secret' => $this->credentials->getConsumerSecret(),
 119              'redirect_uri' => $this->credentials->getCallbackUrl(),
 120              'code' => $code,
 121              'grant_type' => 'authorization_code',
 122          ];
 123   
 124          $responseBody = $this->httpClient->retrieveResponse(
 125              $this->getAccessTokenEndpoint(),
 126              $bodyParams,
 127              $this->getExtraOAuthHeaders()
 128          );
 129          $token = $this->parseAccessTokenResponse($responseBody);
 130          $this->storage->storeAccessToken($this->service(), $token);
 131   
 132          return $token;
 133      }
 134   
 135      protected function parseAccessTokenResponse($responseBody)
 136      {
 137          $data = json_decode($responseBody, true);
 138   
 139          if ($data === null || !is_array($data)) {
 140              throw new TokenResponseException('Unable to parse response.');
 141          } elseif (isset($data['error'])) {
 142              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
 143          }
 144   
 145          $token = new StdOAuth2Token();
 146          $token->setAccessToken($data['access_token']);
 147   
 148          $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
 149          unset($data['access_token']);
 150          $token->setExtraParams($data);
 151   
 152          return $token;
 153      }
 154  }
 155