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

Buffer.php

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