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

Etsy.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 3.46 KiB


001  <?php
002   
003  namespace OAuth\OAuth1\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\OAuth1\Signature\SignatureInterface;
012  use OAuth\OAuth1\Token\StdOAuth1Token;
013   
014  class Etsy extends AbstractService
015  {
016      protected $scopes = [];
017   
018      public function __construct(
019          CredentialsInterface $credentials,
020          ClientInterface $httpClient,
021          TokenStorageInterface $storage,
022          SignatureInterface $signature,
023          ?UriInterface $baseApiUri = null
024      ) {
025          parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
026   
027          if (null === $baseApiUri) {
028              $this->baseApiUri = new Uri('https://openapi.etsy.com/v2/');
029          }
030      }
031   
032      /**
033       * {@inheritdoc}
034       */
035      public function getRequestTokenEndpoint()
036      {
037          $uri = new Uri($this->baseApiUri . 'oauth/request_token');
038          $scopes = $this->getScopes();
039   
040          if (count($scopes)) {
041              $uri->setQuery('scope=' . implode('%20', $scopes));
042          }
043   
044          return $uri;
045      }
046   
047      /**
048       * {@inheritdoc}
049       */
050      public function getAuthorizationEndpoint()
051      {
052          return new Uri($this->baseApiUri);
053      }
054   
055      /**
056       * {@inheritdoc}
057       */
058      public function getAccessTokenEndpoint()
059      {
060          return new Uri($this->baseApiUri . 'oauth/access_token');
061      }
062   
063      /**
064       * {@inheritdoc}
065       */
066      protected function parseRequestTokenResponse($responseBody)
067      {
068          parse_str($responseBody, $data);
069   
070          if (null === $data || !is_array($data)) {
071              throw new TokenResponseException('Unable to parse response.');
072          } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
073              throw new TokenResponseException('Error in retrieving token.');
074          }
075   
076          return $this->parseAccessTokenResponse($responseBody);
077      }
078   
079      /**
080       * {@inheritdoc}
081       */
082      protected function parseAccessTokenResponse($responseBody)
083      {
084          parse_str($responseBody, $data);
085   
086          if (null === $data || !is_array($data)) {
087              throw new TokenResponseException('Unable to parse response.');
088          } elseif (isset($data['error'])) {
089              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
090          }
091   
092          $token = new StdOAuth1Token();
093   
094          $token->setRequestToken($data['oauth_token']);
095          $token->setRequestTokenSecret($data['oauth_token_secret']);
096          $token->setAccessToken($data['oauth_token']);
097          $token->setAccessTokenSecret($data['oauth_token_secret']);
098   
099          $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
100          unset($data['oauth_token'], $data['oauth_token_secret']);
101          $token->setExtraParams($data);
102   
103          return $token;
104      }
105   
106      /**
107       * Set the scopes for permissions.
108       *
109       * @see https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes
110       *
111       * @return $this
112       */
113      public function setScopes(array $scopes)
114      {
115          if (!is_array($scopes)) {
116              $scopes = [];
117          }
118   
119          $this->scopes = $scopes;
120   
121          return $this;
122      }
123   
124      /**
125       * Return the defined scopes.
126       *
127       * @return array
128       */
129      public function getScopes()
130      {
131          return $this->scopes;
132      }
133  }
134