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

ParrotFlowerPower.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.86 KiB


 001  <?php
 002  /**
 003   * ParrotFlowerPower service.
 004   *
 005   * @author  Pedro Amorim <contact@pamorim.fr>
 006   * @license http://www.opensource.org/licenses/mit-license.html MIT License
 007   * @link    https://flowerpowerdev.parrot.com/projects/flower-power-web-service-api/wiki
 008   */
 009   
 010  namespace OAuth\OAuth2\Service;
 011   
 012  use OAuth\OAuth2\Token\StdOAuth2Token;
 013  use OAuth\Common\Http\Exception\TokenResponseException;
 014  use OAuth\Common\Http\Uri\Uri;
 015  use OAuth\Common\Consumer\CredentialsInterface;
 016  use OAuth\Common\Http\Client\ClientInterface;
 017  use OAuth\Common\Storage\TokenStorageInterface;
 018  use OAuth\Common\Http\Uri\UriInterface;
 019  use OAuth\OAuth2\Service\Exception\MissingRefreshTokenException;
 020  use OAuth\Common\Token\TokenInterface;
 021   
 022  /**
 023   * ParrotFlowerPower service.
 024   *
 025   * @author  Pedro Amorim <contact@pamorim.fr>
 026   * @license http://www.opensource.org/licenses/mit-license.html MIT License
 027   * @link    https://flowerpowerdev.parrot.com/projects/flower-power-web-service-api/wiki
 028   */
 029  class ParrotFlowerPower extends AbstractService
 030  {
 031   
 032      public function __construct(
 033          CredentialsInterface $credentials,
 034          ClientInterface $httpClient,
 035          TokenStorageInterface $storage,
 036          $scopes = array(),
 037          UriInterface $baseApiUri = null
 038      ) {
 039          parent::__construct(
 040              $credentials,
 041              $httpClient,
 042              $storage,
 043              $scopes,
 044              $baseApiUri,
 045              true
 046          );
 047   
 048          if (null === $baseApiUri) {
 049              $this->baseApiUri = new Uri('https://apiflowerpower.parrot.com/');
 050          }
 051      }
 052   
 053      /**
 054       * {@inheritdoc}
 055       */
 056      public function getAuthorizationEndpoint()
 057      {
 058          return new Uri($this->baseApiUri.'oauth2/v1/authorize');
 059   
 060      }
 061   
 062      /**
 063       * {@inheritdoc}
 064       */
 065      public function getAccessTokenEndpoint()
 066      {
 067          return new Uri($this->baseApiUri.'user/v1/authenticate');
 068      }
 069   
 070      /**
 071       * {@inheritdoc}
 072       */
 073      protected function getAuthorizationMethod()
 074      {
 075          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
 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(
 089                  'Error in retrieving token: "' . $data['error'] . '"'
 090              );
 091          }
 092   
 093          $token = new StdOAuth2Token();
 094          $token->setAccessToken($data['access_token']);
 095          $token->setLifetime($data['expires_in']);
 096   
 097          if (isset($data['refresh_token'])) {
 098              $token->setRefreshToken($data['refresh_token']);
 099              unset($data['refresh_token']);
 100          }
 101   
 102          unset($data['access_token']);
 103          unset($data['expires_in']);
 104   
 105          $token->setExtraParams($data);
 106   
 107          return $token;
 108      }
 109   
 110   
 111      /**
 112       * Parrot use a different endpoint for refresh a token
 113       *
 114       * {@inheritdoc}
 115       */
 116      public function refreshAccessToken(TokenInterface $token)
 117      {
 118          $refreshToken = $token->getRefreshToken();
 119   
 120          if (empty($refreshToken)) {
 121              throw new MissingRefreshTokenException();
 122          }
 123   
 124          $parameters = array(
 125              'grant_type'    => 'refresh_token',
 126              'type'          => 'web_server',
 127              'client_id'     => $this->credentials->getConsumerId(),
 128              'client_secret' => $this->credentials->getConsumerSecret(),
 129              'refresh_token' => $refreshToken,
 130          );
 131   
 132          $responseBody = $this->httpClient->retrieveResponse(
 133              new Uri($this->baseApiUri.'user/v1/refresh'),
 134              $parameters,
 135              $this->getExtraOAuthHeaders()
 136          );
 137          $token = $this->parseAccessTokenResponse($responseBody);
 138          $this->storage->storeAccessToken($this->service(), $token);
 139   
 140          return $token;
 141      }
 142  }
 143