@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * Implements an abstract OAuth2 provider with all methods required by the OAuth2Interface. |
29 | 29 | * It also implements the ClientCredentials, CSRFToken and TokenRefresh interfaces in favor over traits. |
30 | 30 | */ |
31 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
31 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Specifies the authentication method: |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | 'type' => 'web_server', |
86 | 86 | ]); |
87 | 87 | |
88 | - if(!empty($scopes)){ |
|
88 | + if (!empty($scopes)) { |
|
89 | 89 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
90 | 90 | } |
91 | 91 | |
92 | - if($this instanceof CSRFToken){ |
|
92 | + if ($this instanceof CSRFToken) { |
|
93 | 93 | $params = $this->setState($params); |
94 | 94 | } |
95 | 95 | |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | // silly amazon sends compressed data... |
112 | 112 | $data = json_decode(decompress_content($response), true, 512, JSON_THROW_ON_ERROR); |
113 | 113 | |
114 | - if(!is_array($data)){ |
|
114 | + if (!is_array($data)) { |
|
115 | 115 | throw new ProviderException('unable to parse token response'); |
116 | 116 | } |
117 | 117 | |
118 | - foreach(['error_description', 'error'] as $field){ |
|
118 | + foreach (['error_description', 'error'] as $field) { |
|
119 | 119 | |
120 | - if(isset($data[$field])){ |
|
120 | + if (isset($data[$field])) { |
|
121 | 121 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
122 | 122 | } |
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - if(!isset($data['access_token'])){ |
|
126 | + if (!isset($data['access_token'])) { |
|
127 | 127 | throw new ProviderException('token missing'); |
128 | 128 | } |
129 | 129 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function getAccessToken(string $code, string $state = null):AccessToken{ |
148 | 148 | |
149 | - if($this instanceof CSRFToken){ |
|
149 | + if ($this instanceof CSRFToken) { |
|
150 | 150 | $this->checkState($state); |
151 | 151 | } |
152 | 152 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | ->withHeader('Accept-Encoding', 'identity') |
165 | 165 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))); |
166 | 166 | |
167 | - foreach($this->authHeaders as $header => $value){ |
|
167 | + foreach ($this->authHeaders as $header => $value) { |
|
168 | 168 | $request = $request->withHeader($header, $value); |
169 | 169 | } |
170 | 170 | |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{ |
182 | 182 | |
183 | - if($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER){ |
|
183 | + if ($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER) { |
|
184 | 184 | return $request->withHeader('Authorization', $this->authMethodHeader.' '.$token->accessToken); |
185 | 185 | } |
186 | 186 | |
187 | - if($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY){ |
|
187 | + if ($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY) { |
|
188 | 188 | $uri = Query::merge((string)$request->getUri(), [$this->authMethodQuery => $token->accessToken]); |
189 | 189 | |
190 | 190 | return $request->withUri($this->uriFactory->createUri($uri)); |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function getClientCredentialsToken(array $scopes = null):AccessToken{ |
207 | 207 | |
208 | - if(!$this instanceof ClientCredentials){ |
|
208 | + if (!$this instanceof ClientCredentials) { |
|
209 | 209 | throw new ProviderException('client credentials token not supported'); |
210 | 210 | } |
211 | 211 | |
212 | 212 | $params = ['grant_type' => 'client_credentials']; |
213 | 213 | |
214 | - if($scopes !== null){ |
|
214 | + if ($scopes !== null) { |
|
215 | 215 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
216 | 216 | } |
217 | 217 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | ->withBody($this->streamFactory->createStream(http_build_query($params, '', '&', PHP_QUERY_RFC1738))) |
224 | 224 | ; |
225 | 225 | |
226 | - foreach($this->authHeaders as $header => $value){ |
|
226 | + foreach ($this->authHeaders as $header => $value) { |
|
227 | 227 | $request = $request->withAddedHeader($header, $value); |
228 | 228 | } |
229 | 229 | |
@@ -246,17 +246,17 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function refreshAccessToken(AccessToken $token = null):AccessToken{ |
248 | 248 | |
249 | - if(!$this instanceof TokenRefresh){ |
|
249 | + if (!$this instanceof TokenRefresh) { |
|
250 | 250 | throw new ProviderException('token refresh not supported'); |
251 | 251 | } |
252 | 252 | |
253 | - if($token === null){ |
|
253 | + if ($token === null) { |
|
254 | 254 | $token = $this->storage->getAccessToken($this->serviceName); |
255 | 255 | } |
256 | 256 | |
257 | 257 | $refreshToken = $token->refreshToken; |
258 | 258 | |
259 | - if(empty($refreshToken)){ |
|
259 | + if (empty($refreshToken)) { |
|
260 | 260 | throw new ProviderException( |
261 | 261 | sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires)) |
262 | 262 | ); |
@@ -277,13 +277,13 @@ discard block |
||
277 | 277 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))) |
278 | 278 | ; |
279 | 279 | |
280 | - foreach($this->authHeaders as $header => $value){ |
|
280 | + foreach ($this->authHeaders as $header => $value) { |
|
281 | 281 | $request = $request->withAddedHeader($header, $value); |
282 | 282 | } |
283 | 283 | |
284 | 284 | $newToken = $this->parseTokenResponse($this->http->sendRequest($request)); |
285 | 285 | |
286 | - if(empty($newToken->refreshToken)){ |
|
286 | + if (empty($newToken->refreshToken)) { |
|
287 | 287 | $newToken->refreshToken = $refreshToken; |
288 | 288 | } |
289 | 289 | |
@@ -306,17 +306,17 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function checkState(string $state = null):void{ |
308 | 308 | |
309 | - if(!$this instanceof CSRFToken){ |
|
309 | + if (!$this instanceof CSRFToken) { |
|
310 | 310 | throw new ProviderException('CSRF protection not supported'); |
311 | 311 | } |
312 | 312 | |
313 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
313 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
314 | 314 | throw new ProviderException('invalid state for '.$this->serviceName); |
315 | 315 | } |
316 | 316 | |
317 | 317 | $knownState = $this->storage->getCSRFState($this->serviceName); |
318 | 318 | |
319 | - if(!hash_equals($knownState, $state)){ |
|
319 | + if (!hash_equals($knownState, $state)) { |
|
320 | 320 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
321 | 321 | } |
322 | 322 | |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public function setState(array $params):array{ |
338 | 338 | |
339 | - if(!$this instanceof CSRFToken){ |
|
339 | + if (!$this instanceof CSRFToken) { |
|
340 | 340 | throw new ProviderException('CSRF protection not supported'); |
341 | 341 | } |
342 | 342 | |
343 | - if(!isset($params['state'])){ |
|
343 | + if (!isset($params['state'])) { |
|
344 | 344 | $params['state'] = sha1(random_bytes(256)); |
345 | 345 | } |
346 | 346 |
@@ -39,6 +39,6 @@ |
||
39 | 39 | * @property int $retries |
40 | 40 | * @property array $curl_multi_options |
41 | 41 | */ |
42 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
42 | +class OAuthOptions extends SettingsContainerAbstract { |
|
43 | 43 | use OAuthOptionsTrait; |
44 | 44 | } |