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

Harvest.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 4.03 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\Common\Token\TokenInterface;
012  use OAuth\OAuth2\Token\StdOAuth2Token;
013   
014  class Harvest extends AbstractService
015  {
016      public function __construct(
017          CredentialsInterface $credentials,
018          ClientInterface $httpClient,
019          TokenStorageInterface $storage,
020          $scopes = [],
021          ?UriInterface $baseApiUri = null
022      ) {
023          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
024   
025          if (null === $baseApiUri) {
026              $this->baseApiUri = new Uri('https://api.harvestapp.com/');
027          }
028      }
029   
030      /**
031       * {@inheritdoc}
032       */
033      public function getAuthorizationUri(array $additionalParameters = [])
034      {
035          $parameters = array_merge(
036              $additionalParameters,
037              [
038                  'client_id' => $this->credentials->getConsumerId(),
039                  'redirect_uri' => $this->credentials->getCallbackUrl(),
040                  'state' => 'optional-csrf-token',
041                  'response_type' => 'code',
042              ]
043          );
044   
045          // Build the url
046          $url = clone $this->getAuthorizationEndpoint();
047          foreach ($parameters as $key => $val) {
048              $url->addToQuery($key, $val);
049          }
050   
051          return $url;
052      }
053   
054      /**
055       * {@inheritdoc}
056       */
057      public function getAuthorizationEndpoint()
058      {
059          return new Uri('https://api.harvestapp.com/oauth2/authorize');
060      }
061   
062      /**
063       * {@inheritdoc}
064       */
065      public function getAccessTokenEndpoint()
066      {
067          return new Uri('https://api.harvestapp.com/oauth2/token');
068      }
069   
070      /**
071       * {@inheritdoc}
072       */
073      protected function getAuthorizationMethod()
074      {
075          return static::AUTHORIZATION_METHOD_QUERY_STRING;
076      }
077   
078      /**
079       * {@inheritdoc}
080       */
081      protected function parseAccessTokenResponse($responseBody)
082      {
083          $data = json_decode($responseBody, true);
084   
085          if (null === $data || !is_array($data)) {
086              throw new TokenResponseException('Unable to parse response.');
087          } elseif (isset($data['error'])) {
088              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
089          }
090   
091          $token = new StdOAuth2Token();
092          $token->setAccessToken($data['access_token']);
093          $token->setLifetime($data['expires_in']);
094          $token->setRefreshToken($data['refresh_token']);
095   
096          unset($data['access_token']);
097   
098          $token->setExtraParams($data);
099   
100          return $token;
101      }
102   
103      /**
104       * Refreshes an OAuth2 access token.
105       *
106       * @return TokenInterface $token
107       */
108      public function refreshAccessToken(TokenInterface $token)
109      {
110          $refreshToken = $token->getRefreshToken();
111   
112          if (empty($refreshToken)) {
113              throw new MissingRefreshTokenException();
114          }
115   
116          $parameters = [
117              'grant_type' => 'refresh_token',
118              'type' => 'web_server',
119              'client_id' => $this->credentials->getConsumerId(),
120              'client_secret' => $this->credentials->getConsumerSecret(),
121              'refresh_token' => $refreshToken,
122          ];
123   
124          $responseBody = $this->httpClient->retrieveResponse(
125              $this->getAccessTokenEndpoint(),
126              $parameters,
127              $this->getExtraOAuthHeaders()
128          );
129          $token = $this->parseAccessTokenResponse($responseBody);
130          $this->storage->storeAccessToken($this->service(), $token);
131   
132          return $token;
133      }
134   
135      /**
136       * @return array
137       */
138      protected function getExtraOAuthHeaders()
139      {
140          return ['Accept' => 'application/json'];
141      }
142   
143      /**
144       * Return any additional headers always needed for this service implementation's API calls.
145       *
146       * @return array
147       */
148      protected function getExtraApiHeaders()
149      {
150          return ['Accept' => 'application/json'];
151      }
152  }
153