@@ -27,7 +27,7 @@ |
||
| 27 | 27 | * @property string|null $applicationURL |
| 28 | 28 | * @property string|null $userRevokeURL |
| 29 | 29 | */ |
| 30 | -interface OAuthInterface extends ClientInterface{ |
|
| 30 | +interface OAuthInterface extends ClientInterface { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Prepares the URL with optional $params which redirects to the provider's authorization prompt |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | /** |
| 14 | 14 | * Indicates whether the service is capable of invalidating access tokens |
| 15 | 15 | */ |
| 16 | -interface TokenInvalidate{ |
|
| 16 | +interface TokenInvalidate { |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Allows to invalidate an access token |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * Implements an abstract OAuth provider with all methods required by the OAuthInterface. |
| 38 | 38 | * It also implements a magic getter that allows to access the properties listed below. |
| 39 | 39 | */ |
| 40 | -abstract class OAuthProvider implements OAuthInterface{ |
|
| 40 | +abstract class OAuthProvider implements OAuthInterface { |
|
| 41 | 41 | |
| 42 | 42 | protected const ALLOWED_PROPERTIES = [ |
| 43 | 43 | 'apiDocs', 'apiURL', 'applicationURL', 'serviceName', 'userRevokeURL' |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | ClientInterface $http, |
| 142 | 142 | OAuthOptions|SettingsContainerInterface $options, |
| 143 | 143 | LoggerInterface $logger = null |
| 144 | - ){ |
|
| 144 | + ) { |
|
| 145 | 145 | $this->http = $http; |
| 146 | 146 | $this->storage = new MemoryStorage; |
| 147 | 147 | $this->options = $options; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function __get(string $name):mixed{ |
| 166 | 166 | |
| 167 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
| 167 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
| 168 | 168 | return $this->{$name}; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -261,28 +261,28 @@ discard block |
||
| 261 | 261 | $request = $this->requestFactory |
| 262 | 262 | ->createRequest($method ?? 'GET', QueryUtil::merge($this->getRequestTarget($path), $params ?? [])); |
| 263 | 263 | |
| 264 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
| 264 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
| 265 | 265 | $request = $request->withAddedHeader($header, $value); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if($request->hasHeader('content-type')){ |
|
| 268 | + if ($request->hasHeader('content-type')) { |
|
| 269 | 269 | $contentType = strtolower($request->getHeaderLine('content-type')); |
| 270 | 270 | |
| 271 | - if(is_array($body)){ |
|
| 272 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
| 271 | + if (is_array($body)) { |
|
| 272 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
| 273 | 273 | $body = $this->streamFactory->createStream(QueryUtil::build($body, PHP_QUERY_RFC1738)); |
| 274 | 274 | } |
| 275 | - elseif(in_array($contentType, ['application/json', 'application/vnd.api+json'])){ |
|
| 275 | + elseif (in_array($contentType, ['application/json', 'application/vnd.api+json'])) { |
|
| 276 | 276 | $body = $this->streamFactory->createStream(json_encode($body)); |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | - elseif(is_string($body)){ |
|
| 279 | + elseif (is_string($body)) { |
|
| 280 | 280 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
| 281 | 281 | $body = $this->streamFactory->createStream($body); |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - if($body instanceof StreamInterface){ |
|
| 285 | + if ($body instanceof StreamInterface) { |
|
| 286 | 286 | $request = $request |
| 287 | 287 | ->withBody($body) |
| 288 | 288 | ->withHeader('Content-length', (string)$body->getSize()) |
@@ -304,18 +304,18 @@ discard block |
||
| 304 | 304 | protected function getRequestTarget(string $uri):string{ |
| 305 | 305 | $parsedURL = QueryUtil::parseUrl($uri); |
| 306 | 306 | |
| 307 | - if(!isset($parsedURL['path'])){ |
|
| 307 | + if (!isset($parsedURL['path'])) { |
|
| 308 | 308 | throw new ProviderException('invalid path'); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // for some reason we were given a host name |
| 312 | - if(isset($parsedURL['host'])){ |
|
| 312 | + if (isset($parsedURL['host'])) { |
|
| 313 | 313 | $api = QueryUtil::parseUrl($this->apiURL); |
| 314 | 314 | $host = $api['host'] ?? null; |
| 315 | 315 | |
| 316 | 316 | // back out if it doesn't match |
| 317 | - if($parsedURL['host'] !== $host){ |
|
| 318 | - throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'] , $host)); |
|
| 317 | + if ($parsedURL['host'] !== $host) { |
|
| 318 | + throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'], $host)); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | // we explicitly ignore any existing parameters here |
@@ -332,15 +332,15 @@ discard block |
||
| 332 | 332 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
| 333 | 333 | |
| 334 | 334 | // get authorization only if we request the provider API |
| 335 | - if(str_starts_with((string)$request->getUri(), $this->apiURL)){ |
|
| 335 | + if (str_starts_with((string)$request->getUri(), $this->apiURL)) { |
|
| 336 | 336 | $token = $this->storage->getAccessToken($this->serviceName); |
| 337 | 337 | |
| 338 | 338 | // attempt to refresh an expired token |
| 339 | - if( |
|
| 339 | + if ( |
|
| 340 | 340 | $this instanceof TokenRefresh |
| 341 | 341 | && $this->options->tokenAutoRefresh |
| 342 | 342 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
| 343 | - ){ |
|
| 343 | + ) { |
|
| 344 | 344 | $token = $this->refreshAccessToken($token); |
| 345 | 345 | } |
| 346 | 346 | |
@@ -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 | * Attempts to refresh an existing AccessToken with an associated refresh token and returns a fresh AccessToken. |