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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ParrotFlowerPower.php
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 *
008 * @see https://flowerpowerdev.parrot.com/projects/flower-power-web-service-api/wiki
009 */
010
011 namespace OAuth\OAuth2\Service;
012
013 use OAuth\Common\Consumer\CredentialsInterface;
014 use OAuth\Common\Http\Client\ClientInterface;
015 use OAuth\Common\Http\Exception\TokenResponseException;
016 use OAuth\Common\Http\Uri\Uri;
017 use OAuth\Common\Http\Uri\UriInterface;
018 use OAuth\Common\Storage\TokenStorageInterface;
019 use OAuth\Common\Token\TokenInterface;
020 use OAuth\OAuth2\Service\Exception\MissingRefreshTokenException;
021 use OAuth\OAuth2\Token\StdOAuth2Token;
022
023 /**
024 * ParrotFlowerPower service.
025 *
026 * @author Pedro Amorim <contact@pamorim.fr>
027 * @license http://www.opensource.org/licenses/mit-license.html MIT License
028 *
029 * @see https://flowerpowerdev.parrot.com/projects/flower-power-web-service-api/wiki
030 */
031 class ParrotFlowerPower extends AbstractService
032 {
033 public function __construct(
034 CredentialsInterface $credentials,
035 ClientInterface $httpClient,
036 TokenStorageInterface $storage,
037 $scopes = [],
038 ?UriInterface $baseApiUri = null
039 ) {
040 parent::__construct(
041 $credentials,
042 $httpClient,
043 $storage,
044 $scopes,
045 $baseApiUri,
046 true
047 );
048
049 if (null === $baseApiUri) {
050 $this->baseApiUri = new Uri('https://apiflowerpower.parrot.com/');
051 }
052 }
053
054 /**
055 * {@inheritdoc}
056 */
057 public function getAuthorizationEndpoint()
058 {
059 return new Uri($this->baseApiUri . 'oauth2/v1/authorize');
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'], $data['expires_in']);
103
104 $token->setExtraParams($data);
105
106 return $token;
107 }
108
109 /**
110 * Parrot use a different endpoint for refresh a token.
111 *
112 * {@inheritdoc}
113 */
114 public function refreshAccessToken(TokenInterface $token)
115 {
116 $refreshToken = $token->getRefreshToken();
117
118 if (empty($refreshToken)) {
119 throw new MissingRefreshTokenException();
120 }
121
122 $parameters = [
123 'grant_type' => 'refresh_token',
124 'type' => 'web_server',
125 'client_id' => $this->credentials->getConsumerId(),
126 'client_secret' => $this->credentials->getConsumerSecret(),
127 'refresh_token' => $refreshToken,
128 ];
129
130 $responseBody = $this->httpClient->retrieveResponse(
131 new Uri($this->baseApiUri . 'user/v1/refresh'),
132 $parameters,
133 $this->getExtraOAuthHeaders()
134 );
135 $token = $this->parseAccessTokenResponse($responseBody);
136 $this->storage->storeAccessToken($this->service(), $token);
137
138 return $token;
139 }
140 }
141