@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @property string $serviceName |
40 | 40 | * @property string|null $userRevokeURL |
41 | 41 | */ |
42 | -abstract class OAuthProvider implements OAuthInterface{ |
|
42 | +abstract class OAuthProvider implements OAuthInterface { |
|
43 | 43 | use LoggerAwareTrait; |
44 | 44 | |
45 | 45 | protected const ALLOWED_PROPERTIES = [ |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | OAuthStorageInterface $storage, |
154 | 154 | SettingsContainerInterface $options, |
155 | 155 | LoggerInterface $logger = null |
156 | - ){ |
|
156 | + ) { |
|
157 | 157 | $this->http = $http; |
158 | 158 | $this->storage = $storage; |
159 | 159 | $this->options = $options; |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | |
166 | 166 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
167 | 167 | |
168 | - if(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
168 | + if (!empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
169 | 169 | $this->endpoints = new $this->endpointMap; |
170 | 170 | |
171 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
171 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
172 | 172 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
173 | 173 | } |
174 | 174 | |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @return mixed|null |
183 | 183 | */ |
184 | - public function __get(string $name){ |
|
184 | + public function __get(string $name) { |
|
185 | 185 | |
186 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
186 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
187 | 187 | return $this->{$name}; |
188 | 188 | } |
189 | 189 | |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function __call(string $endpointName, array $arguments):ResponseInterface{ |
246 | 246 | |
247 | - if(!$this->endpoints instanceof EndpointMap){ |
|
247 | + if (!$this->endpoints instanceof EndpointMap) { |
|
248 | 248 | throw new ApiClientException('MagicAPI not available'); |
249 | 249 | } |
250 | 250 | |
251 | - if(!isset($this->endpoints->{$endpointName})){ |
|
251 | + if (!isset($this->endpoints->{$endpointName})) { |
|
252 | 252 | throw new ApiClientException('endpoint not found: "'.$endpointName.'"'); |
253 | 253 | } |
254 | 254 | |
@@ -261,21 +261,21 @@ discard block |
||
261 | 261 | $path_elements = $m['path_elements'] ?? []; |
262 | 262 | $params_in_url = count($path_elements); |
263 | 263 | $params = $arguments[$params_in_url] ?? []; |
264 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
264 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
265 | 265 | |
266 | - if($params_in_url > 0){ |
|
266 | + if ($params_in_url > 0) { |
|
267 | 267 | |
268 | - if(count($urlparams) < $params_in_url){ |
|
268 | + if (count($urlparams) < $params_in_url) { |
|
269 | 269 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
270 | 270 | } |
271 | 271 | |
272 | 272 | $endpoint = sprintf($endpoint, ...$urlparams); |
273 | 273 | } |
274 | 274 | |
275 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
275 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
276 | 276 | $body = $arguments[$params_in_url + 1] ?? $params; |
277 | 277 | |
278 | - if($params === $body){ |
|
278 | + if ($params === $body) { |
|
279 | 279 | $params = []; |
280 | 280 | } |
281 | 281 | |
@@ -325,28 +325,28 @@ discard block |
||
325 | 325 | $request = $this->requestFactory |
326 | 326 | ->createRequest($method ?? 'GET', merge_query($this->apiURL.$path, $params ?? [])); |
327 | 327 | |
328 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
328 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
329 | 329 | $request = $request->withAddedHeader($header, $value); |
330 | 330 | } |
331 | 331 | |
332 | - if($request->hasHeader('content-type')){ |
|
332 | + if ($request->hasHeader('content-type')) { |
|
333 | 333 | $contentType = strtolower($request->getHeaderLine('content-type')); |
334 | 334 | |
335 | - if(is_array($body)){ |
|
336 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
335 | + if (is_array($body)) { |
|
336 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
337 | 337 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
338 | 338 | } |
339 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
339 | + elseif ($contentType === 'application/json' || $contentType === 'application/vnd.api+json') { |
|
340 | 340 | $body = $this->streamFactory->createStream(json_encode($body)); |
341 | 341 | } |
342 | 342 | } |
343 | - elseif(is_string($body)){ |
|
343 | + elseif (is_string($body)) { |
|
344 | 344 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
345 | 345 | $body = $this->streamFactory->createStream($body); |
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
349 | - if($body instanceof StreamInterface){ |
|
349 | + if ($body instanceof StreamInterface) { |
|
350 | 350 | $request = $request |
351 | 351 | ->withBody($body) |
352 | 352 | ->withHeader('Content-length', (string)$body->getSize()) |
@@ -362,15 +362,15 @@ discard block |
||
362 | 362 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
363 | 363 | |
364 | 364 | // get authorization only if we request the provider API |
365 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
365 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
366 | 366 | $token = $this->storage->getAccessToken($this->serviceName); |
367 | 367 | |
368 | 368 | // attempt to refresh an expired token |
369 | - if( |
|
369 | + if ( |
|
370 | 370 | $this instanceof TokenRefresh |
371 | 371 | && $this->options->tokenAutoRefresh |
372 | 372 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
373 | - ){ |
|
373 | + ) { |
|
374 | 374 | $token = $this->refreshAccessToken($token); |
375 | 375 | } |
376 | 376 |
@@ -335,12 +335,10 @@ |
||
335 | 335 | if(is_array($body)){ |
336 | 336 | if($contentType === 'application/x-www-form-urlencoded'){ |
337 | 337 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
338 | - } |
|
339 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
338 | + } elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
340 | 339 | $body = $this->streamFactory->createStream(json_encode($body)); |
341 | 340 | } |
342 | - } |
|
343 | - elseif(is_string($body)){ |
|
341 | + } elseif(is_string($body)){ |
|
344 | 342 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
345 | 343 | $body = $this->streamFactory->createStream($body); |
346 | 344 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | /** |
14 | 14 | * The settings for the OAuth provider |
15 | 15 | */ |
16 | -trait OAuthOptionsTrait{ |
|
16 | +trait OAuthOptionsTrait { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * The application key (or id) given by your provider |
@@ -16,7 +16,7 @@ |
||
16 | 16 | /** |
17 | 17 | * Specifies the methods required for an OAuth storage adapter |
18 | 18 | */ |
19 | -interface OAuthStorageInterface extends LoggerAwareInterface{ |
|
19 | +interface OAuthStorageInterface extends LoggerAwareInterface { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Stores an AccessToken for the given $service |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Implements a memory storage adapter. Memory storage is not persistent as tokens are only stored during script runtime. |
19 | 19 | */ |
20 | -class MemoryStorage extends OAuthStorageAbstract{ |
|
20 | +class MemoryStorage extends OAuthStorageAbstract { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * the token storage array |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getAccessToken(string $service):AccessToken{ |
45 | 45 | |
46 | - if($this->hasAccessToken($service)){ |
|
46 | + if ($this->hasAccessToken($service)) { |
|
47 | 47 | return $this->tokens[$service]; |
48 | 48 | } |
49 | 49 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function clearAccessToken(string $service):bool{ |
64 | 64 | |
65 | - if(array_key_exists($service, $this->tokens)){ |
|
65 | + if (array_key_exists($service, $this->tokens)) { |
|
66 | 66 | unset($this->tokens[$service]); |
67 | 67 | } |
68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function clearAllAccessTokens():bool{ |
76 | 76 | |
77 | - foreach(array_keys($this->tokens) as $service){ |
|
77 | + foreach (array_keys($this->tokens) as $service) { |
|
78 | 78 | unset($this->tokens[$service]); |
79 | 79 | } |
80 | 80 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function getCSRFState(string $service):string{ |
99 | 99 | |
100 | - if($this->hasCSRFState($service)){ |
|
100 | + if ($this->hasCSRFState($service)) { |
|
101 | 101 | return $this->states[$service]; |
102 | 102 | } |
103 | 103 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function clearCSRFState(string $service):bool{ |
118 | 118 | |
119 | - if(array_key_exists($service, $this->states)){ |
|
119 | + if (array_key_exists($service, $this->states)) { |
|
120 | 120 | unset($this->states[$service]); |
121 | 121 | } |
122 | 122 |
@@ -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 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
34 | 34 | * @param \Psr\Log\LoggerInterface|null $logger |
35 | 35 | */ |
36 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
36 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
37 | 37 | $this->options = $options ?? new OAuthOptions; |
38 | 38 | |
39 | 39 | $this->setLogger($logger ?? new NullLogger); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function fromStorage($data):AccessToken{ |
55 | 55 | |
56 | - if(!is_string($data)){ |
|
56 | + if (!is_string($data)) { |
|
57 | 57 | throw new OAuthStorageException('invalid data'); |
58 | 58 | } |
59 | 59 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Implements a session storage adapter. Session storage is half persistent as tokens are stored for the duration of the session. |
22 | 22 | */ |
23 | -class SessionStorage extends OAuthStorageAbstract{ |
|
23 | +class SessionStorage extends OAuthStorageAbstract { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * the key name for the token storage array in $_SESSION |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
39 | 39 | */ |
40 | - public function __construct(SettingsContainerInterface $options = null){ |
|
40 | + public function __construct(SettingsContainerInterface $options = null) { |
|
41 | 41 | parent::__construct($options); |
42 | 42 | |
43 | 43 | $this->tokenVar = $this->options->sessionTokenVar; |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | |
46 | 46 | // Determine if the session has started. |
47 | 47 | // @link http://stackoverflow.com/a/18542272/1470961 |
48 | - if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){ |
|
48 | + if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) { |
|
49 | 49 | session_start(); |
50 | 50 | } |
51 | 51 | |
52 | - if(!isset($_SESSION[$this->tokenVar])){ |
|
52 | + if (!isset($_SESSION[$this->tokenVar])) { |
|
53 | 53 | $_SESSION[$this->tokenVar] = []; |
54 | 54 | } |
55 | 55 | |
56 | - if(!isset($_SESSION[$this->stateVar])){ |
|
56 | + if (!isset($_SESSION[$this->stateVar])) { |
|
57 | 57 | $_SESSION[$this->stateVar] = []; |
58 | 58 | } |
59 | 59 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @codeCoverageIgnore |
66 | 66 | */ |
67 | - public function __destruct(){ |
|
68 | - if($this->options->sessionStart){ |
|
67 | + public function __destruct() { |
|
68 | + if ($this->options->sessionStart) { |
|
69 | 69 | session_write_close(); |
70 | 70 | } |
71 | 71 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function getAccessToken(string $service):AccessToken{ |
86 | 86 | |
87 | - if($this->hasAccessToken($service)){ |
|
87 | + if ($this->hasAccessToken($service)) { |
|
88 | 88 | return $this->fromStorage($_SESSION[$this->tokenVar][$service]); |
89 | 89 | } |
90 | 90 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function clearAccessToken(string $service):bool{ |
105 | 105 | |
106 | - if(array_key_exists($service, $_SESSION[$this->tokenVar])){ |
|
106 | + if (array_key_exists($service, $_SESSION[$this->tokenVar])) { |
|
107 | 107 | unset($_SESSION[$this->tokenVar][$service]); |
108 | 108 | } |
109 | 109 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function clearAllAccessTokens():bool{ |
117 | 117 | |
118 | - foreach(array_keys($_SESSION[$this->tokenVar]) as $service){ |
|
118 | + foreach (array_keys($_SESSION[$this->tokenVar]) as $service) { |
|
119 | 119 | unset($_SESSION[$this->tokenVar][$service]); |
120 | 120 | } |
121 | 121 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function getCSRFState(string $service):string{ |
140 | 140 | |
141 | - if($this->hasCSRFState($service)){ |
|
141 | + if ($this->hasCSRFState($service)) { |
|
142 | 142 | return $_SESSION[$this->stateVar][$service]; |
143 | 143 | } |
144 | 144 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function clearCSRFState(string $service):bool{ |
159 | 159 | |
160 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
160 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
161 | 161 | unset($_SESSION[$this->stateVar][$service]); |
162 | 162 | } |
163 | 163 |
@@ -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. |