@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @property string $serviceName |
19 | 19 | * @property \chillerlan\OAuth\Storage\OAuthStorageInterface $storage |
20 | 20 | */ |
21 | -trait OAuth2CSRFTokenTrait{ |
|
21 | +trait OAuth2CSRFTokenTrait { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @param string|null $state |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected function checkState(string $state = null):OAuth2Interface{ |
30 | 30 | |
31 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
31 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
32 | 32 | throw new ProviderException('invalid state for '.$this->serviceName); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $knownState = $this->storage->getCSRFState($this->serviceName); |
36 | 36 | |
37 | - if(!hash_equals($knownState, $state)){ |
|
37 | + if (!hash_equals($knownState, $state)) { |
|
38 | 38 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
39 | 39 | } |
40 | 40 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | protected function setState(array $params):array{ |
51 | 51 | |
52 | - if(!isset($params['state'])){ |
|
52 | + if (!isset($params['state'])) { |
|
53 | 53 | $params['state'] = sha1(random_bytes(256)); |
54 | 54 | } |
55 | 55 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @property \Psr\Http\Message\RequestFactoryInterface $requestFactory |
25 | 25 | * @property \Psr\Http\Message\StreamFactoryInterface $streamFactory |
26 | 26 | */ |
27 | -trait OAuth2ClientCredentialsTrait{ |
|
27 | +trait OAuth2ClientCredentialsTrait { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @param array $scopes |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function getClientCredentialsToken(array $scopes = null):AccessToken{ |
35 | 35 | $params = ['grant_type' => 'client_credentials']; |
36 | 36 | |
37 | - if($scopes !== null){ |
|
37 | + if ($scopes !== null) { |
|
38 | 38 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
39 | 39 | } |
40 | 40 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ->withBody($this->streamFactory->createStream(http_build_query($params, '', '&', PHP_QUERY_RFC1738))) |
46 | 46 | ; |
47 | 47 | |
48 | - foreach($this->authHeaders as $header => $value){ |
|
48 | + foreach ($this->authHeaders as $header => $value) { |
|
49 | 49 | $request = $request->withAddedHeader($header, $value); |
50 | 50 | } |
51 | 51 |
@@ -277,8 +277,7 @@ |
||
277 | 277 | |
278 | 278 | if($contentType === 'application/x-www-form-urlencoded'){ |
279 | 279 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
280 | - } |
|
281 | - elseif($contentType === 'application/json'){ |
|
280 | + } elseif($contentType === 'application/json'){ |
|
282 | 281 | $body = $this->streamFactory->createStream(json_encode($body)); |
283 | 282 | } |
284 | 283 |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
123 | 123 | */ |
124 | - public function __construct(HttpClient $http, OAuthStorageInterface $storage, SettingsContainerInterface $options){ |
|
124 | + public function __construct(HttpClient $http, OAuthStorageInterface $storage, SettingsContainerInterface $options) { |
|
125 | 125 | $this->http = $http; |
126 | 126 | $this->storage = $storage; |
127 | 127 | $this->options = $options; |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | |
134 | 134 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
135 | 135 | |
136 | - if(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
136 | + if (!empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
137 | 137 | $this->endpoints = new $this->endpointMap; |
138 | 138 | |
139 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
139 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
140 | 140 | throw new ApiClientException('invalid endpoint map'); |
141 | 141 | } |
142 | 142 | |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return string|null |
151 | 151 | */ |
152 | - public function __get(string $name){ |
|
152 | + public function __get(string $name) { |
|
153 | 153 | |
154 | - if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL'], true)){ |
|
154 | + if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL'], true)) { |
|
155 | 155 | return null; |
156 | 156 | } |
157 | 157 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function __call(string $name, array $arguments):ResponseInterface{ |
206 | 206 | |
207 | - if(!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)){ |
|
207 | + if (!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)) { |
|
208 | 208 | throw new ApiClientException('endpoint not found'); |
209 | 209 | } |
210 | 210 | |
@@ -217,21 +217,21 @@ discard block |
||
217 | 217 | $path_elements = $m['path_elements'] ?? []; |
218 | 218 | $params_in_url = count($path_elements); |
219 | 219 | $params = $arguments[$params_in_url] ?? []; |
220 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
220 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
221 | 221 | |
222 | - if($params_in_url > 0){ |
|
222 | + if ($params_in_url > 0) { |
|
223 | 223 | |
224 | - if(count($urlparams) < $params_in_url){ |
|
224 | + if (count($urlparams) < $params_in_url) { |
|
225 | 225 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
226 | 226 | } |
227 | 227 | |
228 | 228 | $endpoint = sprintf($endpoint, ...$urlparams); |
229 | 229 | } |
230 | 230 | |
231 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
231 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
232 | 232 | $body = $arguments[$params_in_url + 1] ?? $params; |
233 | 233 | |
234 | - if($params === $body){ |
|
234 | + if ($params === $body) { |
|
235 | 235 | $params = []; |
236 | 236 | } |
237 | 237 | |
@@ -278,32 +278,32 @@ discard block |
||
278 | 278 | $token = $this->storage->getAccessToken($this->serviceName); |
279 | 279 | |
280 | 280 | // attempt to refresh an expired token |
281 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
281 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
282 | 282 | $token = $this->refreshAccessToken($token); |
283 | 283 | } |
284 | 284 | |
285 | 285 | $request = $this->requestFactory |
286 | 286 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params)); |
287 | 287 | |
288 | - foreach(array_merge($this->apiHeaders, $headers) as $header => $value){ |
|
288 | + foreach (array_merge($this->apiHeaders, $headers) as $header => $value) { |
|
289 | 289 | $request = $request->withAddedHeader($header, $value); |
290 | 290 | } |
291 | 291 | |
292 | 292 | $request = $this->getRequestAuthorization($request, $token); |
293 | 293 | |
294 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
294 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
295 | 295 | $contentType = strtolower($request->getHeaderLine('content-type')); |
296 | 296 | |
297 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
297 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
298 | 298 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
299 | 299 | } |
300 | - elseif($contentType === 'application/json'){ |
|
300 | + elseif ($contentType === 'application/json') { |
|
301 | 301 | $body = $this->streamFactory->createStream(json_encode($body)); |
302 | 302 | } |
303 | 303 | |
304 | 304 | } |
305 | 305 | |
306 | - if($body instanceof StreamInterface){ |
|
306 | + if ($body instanceof StreamInterface) { |
|
307 | 307 | $request = $request->withBody($body); |
308 | 308 | } |
309 | 309 |
@@ -36,6 +36,6 @@ |
||
36 | 36 | * @property string $ca_info |
37 | 37 | * @property int $max_redirects |
38 | 38 | */ |
39 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
39 | +class OAuthOptions extends SettingsContainerAbstract { |
|
40 | 40 | use OAuthOptionsTrait, HTTPOptionsTrait; |
41 | 41 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth; |
14 | 14 | |
15 | -trait OAuthOptionsTrait{ |
|
15 | +trait OAuthOptionsTrait { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @var string |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\OAuth\{Core\AccessToken, OAuthOptions}; |
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | |
18 | -abstract class OAuthStorageAbstract implements OAuthStorageInterface{ |
|
18 | +abstract class OAuthStorageAbstract implements OAuthStorageInterface { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \chillerlan\OAuth\OAuthOptions |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
29 | 29 | */ |
30 | - public function __construct(SettingsContainerInterface $options = null){ |
|
30 | + public function __construct(SettingsContainerInterface $options = null) { |
|
31 | 31 | $this->options = $options ?? new OAuthOptions; |
32 | 32 | } |
33 | 33 |