@@ -15,7 +15,7 @@ |
||
15 | 15 | * |
16 | 16 | * @link https://tools.ietf.org/html/rfc6749#section-10.4 |
17 | 17 | */ |
18 | -interface TokenRefresh{ |
|
18 | +interface TokenRefresh { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Tries to refresh an existing AccessToken with an associated refresh token and returns a fresh AccessToken. |
@@ -15,7 +15,7 @@ |
||
15 | 15 | * |
16 | 16 | * @link https://tools.ietf.org/html/rfc6749#section-4.4 |
17 | 17 | */ |
18 | -interface ClientCredentials{ |
|
18 | +interface ClientCredentials { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Obtains an OAuth2 client credentials token and returns an AccessToken |
@@ -13,7 +13,7 @@ |
||
13 | 13 | /** |
14 | 14 | * Specifies the basic methods for an OAuth1 provider. |
15 | 15 | */ |
16 | -interface OAuth1Interface extends OAuthInterface{ |
|
16 | +interface OAuth1Interface extends OAuthInterface { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Obtains an OAuth1 request token and returns an AccessToken object for use in the authentication request. |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** |
16 | 16 | * Specifies the basic methods for an OAuth2 provider. |
17 | 17 | */ |
18 | -interface OAuth2Interface extends OAuthInterface{ |
|
18 | +interface OAuth2Interface extends OAuthInterface { |
|
19 | 19 | |
20 | 20 | const AUTH_METHOD_HEADER = 1; |
21 | 21 | const AUTH_METHOD_QUERY = 2; |
@@ -15,7 +15,7 @@ |
||
15 | 15 | * |
16 | 16 | * @link https://tools.ietf.org/html/rfc6749#section-10.12 |
17 | 17 | */ |
18 | -interface CSRFToken{ |
|
18 | +interface CSRFToken { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Checks whether the CSRF state was set and verifies against the last known state. |
@@ -404,12 +404,10 @@ |
||
404 | 404 | if(is_array($body)){ |
405 | 405 | if($contentType === 'application/x-www-form-urlencoded'){ |
406 | 406 | $body = $this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738)); |
407 | - } |
|
408 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
407 | + } elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
409 | 408 | $body = $this->streamFactory->createStream(json_encode($body)); |
410 | 409 | } |
411 | - } |
|
412 | - elseif(is_string($body)){ |
|
410 | + } elseif(is_string($body)){ |
|
413 | 411 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
414 | 412 | $body = $this->streamFactory->createStream($body); |
415 | 413 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @property string $serviceName |
42 | 42 | * @property string|null $userRevokeURL |
43 | 43 | */ |
44 | -abstract class OAuthProvider implements OAuthInterface{ |
|
44 | +abstract class OAuthProvider implements OAuthInterface { |
|
45 | 45 | use LoggerAwareTrait; |
46 | 46 | |
47 | 47 | protected const ALLOWED_PROPERTIES = [ |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | OAuthStorageInterface $storage, |
151 | 151 | SettingsContainerInterface $options, |
152 | 152 | LoggerInterface $logger = null |
153 | - ){ |
|
153 | + ) { |
|
154 | 154 | $this->http = $http; |
155 | 155 | $this->storage = $storage; |
156 | 156 | $this->options = $options; |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | |
165 | 165 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
166 | 166 | |
167 | - if(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
167 | + if (!empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
168 | 168 | $this->endpoints = new $this->endpointMap; |
169 | 169 | |
170 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
170 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
171 | 171 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
172 | 172 | } |
173 | 173 | |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @return mixed|null |
182 | 182 | */ |
183 | - public function __get(string $name){ |
|
183 | + public function __get(string $name) { |
|
184 | 184 | |
185 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
185 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
186 | 186 | return $this->{$name}; |
187 | 187 | } |
188 | 188 | |
@@ -251,11 +251,11 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function __call(string $endpointName, array $arguments):ResponseInterface{ |
253 | 253 | |
254 | - if(!$this->endpoints instanceof EndpointMap){ |
|
254 | + if (!$this->endpoints instanceof EndpointMap) { |
|
255 | 255 | throw new ApiClientException('MagicAPI not available'); // @codeCoverageIgnore |
256 | 256 | } |
257 | 257 | |
258 | - if(!isset($this->endpoints->{$endpointName})){ |
|
258 | + if (!isset($this->endpoints->{$endpointName})) { |
|
259 | 259 | throw new ApiClientException('endpoint not found: "'.$endpointName.'"'); |
260 | 260 | } |
261 | 261 | |
@@ -275,25 +275,25 @@ discard block |
||
275 | 275 | $path_element_count = count($path_elements); |
276 | 276 | $query_param_count = count($query_params); |
277 | 277 | |
278 | - if($path_element_count > 0){ |
|
278 | + if ($path_element_count > 0) { |
|
279 | 279 | $path = $this->parsePathElements($path, $path_elements, $path_element_count, $arguments); |
280 | 280 | } |
281 | 281 | |
282 | - if($query_param_count > 0){ |
|
282 | + if ($query_param_count > 0) { |
|
283 | 283 | // $params is the first argument after path segments |
284 | 284 | $params = $arguments[$path_element_count] ?? null; |
285 | 285 | |
286 | - if(is_array($params)){ |
|
286 | + if (is_array($params)) { |
|
287 | 287 | $params = $this->cleanQueryParams($this->removeUnlistedParams($params, $query_params)); |
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body){ |
|
291 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body) { |
|
292 | 292 | // if no query params are present, $body is the first argument after any path segments |
293 | 293 | $argPos = $query_param_count > 0 ? 1 : 0; |
294 | 294 | $body = $arguments[$path_element_count + $argPos] ?? null; |
295 | 295 | |
296 | - if(is_array($body)){ |
|
296 | + if (is_array($body)) { |
|
297 | 297 | $body = $this->cleanBodyParams($body); |
298 | 298 | } |
299 | 299 | } |
@@ -314,13 +314,13 @@ discard block |
||
314 | 314 | // we don't know if all of the given arguments are path elements... |
315 | 315 | $urlparams = array_slice($arguments, 0, $path_element_count); |
316 | 316 | |
317 | - if(count($urlparams) !== $path_element_count){ |
|
317 | + if (count($urlparams) !== $path_element_count) { |
|
318 | 318 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
319 | 319 | } |
320 | 320 | |
321 | - foreach($urlparams as $i => $param){ |
|
321 | + foreach ($urlparams as $i => $param) { |
|
322 | 322 | // ...but we do know that the arguments after the path elements are usually array or null |
323 | - if(!is_scalar($param)){ |
|
323 | + if (!is_scalar($param)) { |
|
324 | 324 | $msg = 'invalid path element value for "%s": %s'; |
325 | 325 | |
326 | 326 | throw new APIClientException(sprintf($msg, $path_elements[$i], var_export($param, true))); |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | protected function removeUnlistedParams(array $params, array $allowed):array{ |
337 | 337 | $query = []; |
338 | 338 | // remove any params that are not listed |
339 | - foreach($params as $key => $value){ |
|
339 | + foreach ($params as $key => $value) { |
|
340 | 340 | |
341 | - if(!in_array($key, $allowed, true)){ |
|
341 | + if (!in_array($key, $allowed, true)) { |
|
342 | 342 | continue; |
343 | 343 | } |
344 | 344 | |
@@ -397,28 +397,28 @@ discard block |
||
397 | 397 | $request = $this->requestFactory |
398 | 398 | ->createRequest($method ?? 'GET', $this->mergeQuery($this->getRequestTarget($path), $params ?? [])); |
399 | 399 | |
400 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
400 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
401 | 401 | $request = $request->withAddedHeader($header, $value); |
402 | 402 | } |
403 | 403 | |
404 | - if($request->hasHeader('content-type')){ |
|
404 | + if ($request->hasHeader('content-type')) { |
|
405 | 405 | $contentType = strtolower($request->getHeaderLine('content-type')); |
406 | 406 | |
407 | - if(is_array($body)){ |
|
408 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
407 | + if (is_array($body)) { |
|
408 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
409 | 409 | $body = $this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738)); |
410 | 410 | } |
411 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
411 | + elseif ($contentType === 'application/json' || $contentType === 'application/vnd.api+json') { |
|
412 | 412 | $body = $this->streamFactory->createStream(json_encode($body)); |
413 | 413 | } |
414 | 414 | } |
415 | - elseif(is_string($body)){ |
|
415 | + elseif (is_string($body)) { |
|
416 | 416 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
417 | 417 | $body = $this->streamFactory->createStream($body); |
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
421 | - if($body instanceof StreamInterface){ |
|
421 | + if ($body instanceof StreamInterface) { |
|
422 | 422 | $request = $request |
423 | 423 | ->withBody($body) |
424 | 424 | ->withHeader('Content-length', (string)$body->getSize()) |
@@ -440,16 +440,16 @@ discard block |
||
440 | 440 | protected function getRequestTarget(string $uri):string{ |
441 | 441 | $parsedURL = QueryUtil::parseUrl($uri); |
442 | 442 | |
443 | - if(!isset($parsedURL['path'])){ |
|
443 | + if (!isset($parsedURL['path'])) { |
|
444 | 444 | throw new ProviderException('invalid path'); |
445 | 445 | } |
446 | 446 | |
447 | 447 | // for some reason we were given a host name |
448 | - if(isset($parsedURL['host'])){ |
|
448 | + if (isset($parsedURL['host'])) { |
|
449 | 449 | |
450 | 450 | // back out if it doesn't match |
451 | 451 | /** @phan-suppress-next-line PhanTypeArraySuspiciousNullable - $this->>apiURL should always return a host */ |
452 | - if($parsedURL['host'] !== QueryUtil::parseUrl($this->apiURL)['host']){ |
|
452 | + if ($parsedURL['host'] !== QueryUtil::parseUrl($this->apiURL)['host']) { |
|
453 | 453 | throw new ProviderException('given host does not match provider host'); |
454 | 454 | } |
455 | 455 | |
@@ -467,15 +467,15 @@ discard block |
||
467 | 467 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
468 | 468 | |
469 | 469 | // get authorization only if we request the provider API |
470 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
470 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
471 | 471 | $token = $this->storage->getAccessToken($this->serviceName); |
472 | 472 | |
473 | 473 | // attempt to refresh an expired token |
474 | - if( |
|
474 | + if ( |
|
475 | 475 | $this instanceof TokenRefresh |
476 | 476 | && $this->options->tokenAutoRefresh |
477 | 477 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
478 | - ){ |
|
478 | + ) { |
|
479 | 479 | $token = $this->refreshAccessToken($token); |
480 | 480 | } |
481 | 481 |
@@ -40,6 +40,6 @@ |
||
40 | 40 | * @property array $curl_multi_options |
41 | 41 | * @property bool $curl_check_OCSP |
42 | 42 | */ |
43 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
43 | +class OAuthOptions extends SettingsContainerAbstract { |
|
44 | 44 | use OAuthOptionsTrait, HTTPOptionsTrait; |
45 | 45 | } |
@@ -83,11 +83,9 @@ |
||
83 | 83 | |
84 | 84 | if(empty($data)){ |
85 | 85 | throw new ProviderException('unable to parse token response'); |
86 | - } |
|
87 | - elseif(isset($data['error'])){ |
|
86 | + } elseif(isset($data['error'])){ |
|
88 | 87 | throw new ProviderException('error retrieving access token: '.$data['error']); |
89 | - } |
|
90 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
88 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
91 | 89 | throw new ProviderException('invalid token'); |
92 | 90 | } |
93 | 91 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Implements an abstract OAuth1 provider with all methods required by the OAuth1Interface. |
23 | 23 | */ |
24 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
24 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * The request OAuth1 token URL |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | ->withHeader('Content-Length', '0') // tumblr requires a content-length header set |
61 | 61 | ; |
62 | 62 | |
63 | - foreach($this->authHeaders as $header => $value){ |
|
63 | + foreach ($this->authHeaders as $header => $value) { |
|
64 | 64 | $request = $request->withAddedHeader($header, $value); |
65 | 65 | } |
66 | 66 | |
@@ -77,20 +77,20 @@ discard block |
||
77 | 77 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
78 | 78 | $data = $this->parseQuery(MessageUtil::decompress($response)); |
79 | 79 | |
80 | - if(empty($data)){ |
|
80 | + if (empty($data)) { |
|
81 | 81 | throw new ProviderException('unable to parse token response'); |
82 | 82 | } |
83 | - elseif(isset($data['error'])){ |
|
83 | + elseif (isset($data['error'])) { |
|
84 | 84 | throw new ProviderException('error retrieving access token: '.$data['error']); |
85 | 85 | } |
86 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
86 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
87 | 87 | throw new ProviderException('invalid token'); |
88 | 88 | } |
89 | 89 | |
90 | - if( |
|
90 | + if ( |
|
91 | 91 | $checkCallbackConfirmed |
92 | 92 | && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') |
93 | - ){ |
|
93 | + ) { |
|
94 | 94 | throw new ProviderException('oauth callback unconfirmed'); |
95 | 95 | } |
96 | 96 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
133 | 133 | $parsed = QueryUtil::parseUrl($url); |
134 | 134 | |
135 | - if(!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)){ |
|
135 | + if (!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)) { |
|
136 | 136 | throw new ProviderException('getSignature: invalid url'); |
137 | 137 | } |
138 | 138 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | ]); |
150 | 150 | |
151 | 151 | // https://tools.ietf.org/html/rfc5849#section-3.4.2 |
152 | - $key = array_map('rawurlencode', [ |
|
152 | + $key = array_map('rawurlencode', [ |
|
153 | 153 | $this->options->secret, |
154 | 154 | $accessTokenSecret ?? '' |
155 | 155 | ]); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $token->accessTokenSecret |
197 | 197 | ); |
198 | 198 | |
199 | - if(isset($query['oauth_session_handle'])){ |
|
199 | + if (isset($query['oauth_session_handle'])) { |
|
200 | 200 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
201 | 201 | } |
202 | 202 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * Implements ab anstract OAuth storage adapter |
21 | 21 | */ |
22 | -abstract class OAuthStorageAbstract implements OAuthStorageInterface{ |
|
22 | +abstract class OAuthStorageAbstract implements OAuthStorageInterface { |
|
23 | 23 | use LoggerAwareTrait; |
24 | 24 | |
25 | 25 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * OAuthStorageAbstract constructor. |
32 | 32 | */ |
33 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | $this->options = $options ?? new OAuthOptions; |
35 | 35 | |
36 | 36 | $this->setLogger($logger ?? new NullLogger); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function fromStorage($data):AccessToken{ |
52 | 52 | |
53 | - if(!is_string($data)){ |
|
53 | + if (!is_string($data)) { |
|
54 | 54 | throw new OAuthStorageException('invalid data'); |
55 | 55 | } |
56 | 56 |