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

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Bitly.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 3.17 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  class Bitly extends AbstractService
014  {
015      public function __construct(
016          CredentialsInterface $credentials,
017          ClientInterface $httpClient,
018          TokenStorageInterface $storage,
019          $scopes = [],
020          ?UriInterface $baseApiUri = null
021      ) {
022          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
023   
024          if (null === $baseApiUri) {
025              $this->baseApiUri = new Uri('https://api-ssl.bitly.com/v3/');
026          }
027      }
028   
029      /**
030       * {@inheritdoc}
031       */
032      public function getAuthorizationEndpoint()
033      {
034          return new Uri('https://bitly.com/oauth/authorize');
035      }
036   
037      /**
038       * {@inheritdoc}
039       */
040      public function getAccessTokenEndpoint()
041      {
042          return new Uri('https://api-ssl.bitly.com/oauth/access_token');
043      }
044   
045      /**
046       * {@inheritdoc}
047       */
048      protected function getAuthorizationMethod()
049      {
050          return static::AUTHORIZATION_METHOD_QUERY_STRING;
051      }
052   
053      /**
054       * {@inheritdoc}
055       */
056      protected function parseAccessTokenResponse($responseBody)
057      {
058          $data = json_decode($responseBody, true);
059   
060          if (null === $data || !is_array($data)) {
061              throw new TokenResponseException('Unable to parse response.');
062          } elseif (isset($data['error'])) {
063              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
064          }
065   
066          $token = new StdOAuth2Token();
067          $token->setAccessToken($data['access_token']);
068          // I'm invincible!!!
069          $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
070          unset($data['access_token']);
071   
072          $token->setExtraParams($data);
073   
074          return $token;
075      }
076   
077      /**
078       * {@inheritdoc}
079       */
080      public function requestAccessToken($code, $state = null)
081      {
082          if (null !== $state) {
083              $this->validateAuthorizationState($state);
084          }
085   
086          $bodyParams = [
087              'code' => $code,
088              'client_id' => $this->credentials->getConsumerId(),
089              'client_secret' => $this->credentials->getConsumerSecret(),
090              'redirect_uri' => $this->credentials->getCallbackUrl(),
091              'grant_type' => 'authorization_code',
092          ];
093   
094          $responseBody = $this->httpClient->retrieveResponse(
095              $this->getAccessTokenEndpoint(),
096              $bodyParams,
097              $this->getExtraOAuthHeaders()
098          );
099   
100          // we can scream what we want that we want bitly to return a json encoded string (format=json), but the
101          // WOAH WATCH YOUR LANGUAGE ;) service doesn't seem to like screaming, hence we need to manually
102          // parse the result
103          $parsedResult = [];
104          parse_str($responseBody, $parsedResult);
105   
106          $token = $this->parseAccessTokenResponse(json_encode($parsedResult));
107          $this->storage->storeAccessToken($this->service(), $token);
108   
109          return $token;
110      }
111  }
112