@@ -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 |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
122 | 122 | */ |
123 | - public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options){ |
|
123 | + public function __construct(HTTPClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options) { |
|
124 | 124 | $this->http = $http; |
125 | 125 | $this->storage = $storage; |
126 | 126 | $this->options = $options; |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | |
133 | 133 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
134 | 134 | |
135 | - if(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
135 | + if (!empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
136 | 136 | $this->endpoints = new $this->endpointMap; |
137 | 137 | |
138 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
138 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
139 | 139 | throw new ApiClientException('invalid endpoint map'); |
140 | 140 | } |
141 | 141 | |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @return string|null |
150 | 150 | */ |
151 | - public function __get(string $name){ |
|
151 | + public function __get(string $name) { |
|
152 | 152 | |
153 | - if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL'], true)){ |
|
153 | + if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL'], true)) { |
|
154 | 154 | return null; |
155 | 155 | } |
156 | 156 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function __call(string $name, array $arguments):ResponseInterface{ |
205 | 205 | |
206 | - if(!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)){ |
|
206 | + if (!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)) { |
|
207 | 207 | throw new ApiClientException('endpoint not found'); |
208 | 208 | } |
209 | 209 | |
@@ -216,21 +216,21 @@ discard block |
||
216 | 216 | $path_elements = $m['path_elements'] ?? []; |
217 | 217 | $params_in_url = count($path_elements); |
218 | 218 | $params = $arguments[$params_in_url] ?? []; |
219 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
219 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
220 | 220 | |
221 | - if($params_in_url > 0){ |
|
221 | + if ($params_in_url > 0) { |
|
222 | 222 | |
223 | - if(count($urlparams) < $params_in_url){ |
|
223 | + if (count($urlparams) < $params_in_url) { |
|
224 | 224 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
225 | 225 | } |
226 | 226 | |
227 | 227 | $endpoint = sprintf($endpoint, ...$urlparams); |
228 | 228 | } |
229 | 229 | |
230 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
230 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
231 | 231 | $body = $arguments[$params_in_url + 1] ?? $params; |
232 | 232 | |
233 | - if($params === $body){ |
|
233 | + if ($params === $body) { |
|
234 | 234 | $params = []; |
235 | 235 | } |
236 | 236 | |
@@ -259,32 +259,32 @@ discard block |
||
259 | 259 | $token = $this->storage->getAccessToken($this->serviceName); |
260 | 260 | |
261 | 261 | // attempt to refresh an expired token |
262 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
262 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
263 | 263 | $token = $this->refreshAccessToken($token); |
264 | 264 | } |
265 | 265 | |
266 | 266 | $request = $this->requestFactory |
267 | 267 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params)); |
268 | 268 | |
269 | - foreach(array_merge($this->apiHeaders, $headers) as $header => $value){ |
|
269 | + foreach (array_merge($this->apiHeaders, $headers) as $header => $value) { |
|
270 | 270 | $request = $request->withAddedHeader($header, $value); |
271 | 271 | } |
272 | 272 | |
273 | 273 | $request = $this->getRequestAuthorization($request, $token); |
274 | 274 | |
275 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
275 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
276 | 276 | $contentType = strtolower($request->getHeaderLine('content-type')); |
277 | 277 | |
278 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
278 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
279 | 279 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
280 | 280 | } |
281 | - elseif($contentType === 'application/json'){ |
|
281 | + elseif ($contentType === 'application/json') { |
|
282 | 282 | $body = $this->streamFactory->createStream(json_encode($body)); |
283 | 283 | } |
284 | 284 | |
285 | 285 | } |
286 | 286 | |
287 | - if($body instanceof StreamInterface){ |
|
287 | + if ($body instanceof StreamInterface) { |
|
288 | 288 | $request = $request->withBody($body); |
289 | 289 | } |
290 | 290 |
@@ -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 |
@@ -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 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
31 | 31 | * @param \Psr\Log\LoggerInterface|null $logger |
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 | $this->logger = $logger ?? new NullLogger; |
36 | 36 | } |
@@ -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 |