@@ -138,11 +138,9 @@ |
||
138 | 138 | |
139 | 139 | if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
140 | 140 | $this->expires = $this::EOL_NEVER_EXPIRES; |
141 | - } |
|
142 | - elseif($expires > $now){ |
|
141 | + } elseif($expires > $now){ |
|
143 | 142 | $this->expires = $expires; |
144 | - } |
|
145 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
143 | + } elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
146 | 144 | $this->expires = $now + $expires; |
147 | 145 | } |
148 | 146 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @property int $expires |
30 | 30 | * @property string $provider |
31 | 31 | */ |
32 | -class AccessToken extends SettingsContainerAbstract{ |
|
32 | +class AccessToken extends SettingsContainerAbstract { |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Denotes an unknown end of life time. |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param iterable|null $properties |
86 | 86 | */ |
87 | - public function __construct(iterable $properties = null){ |
|
87 | + public function __construct(iterable $properties = null) { |
|
88 | 88 | parent::__construct($properties); |
89 | 89 | |
90 | 90 | $this->setExpiry($this->expires); |
@@ -109,19 +109,19 @@ discard block |
||
109 | 109 | public function setExpiry(int $expires = null):AccessToken{ |
110 | 110 | $now = time(); |
111 | 111 | |
112 | - if($expires!== null){ |
|
112 | + if ($expires !== null) { |
|
113 | 113 | $expires = intval($expires); |
114 | 114 | } |
115 | 115 | |
116 | 116 | $this->expires = $this::EOL_UNKNOWN; |
117 | 117 | |
118 | - if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
|
118 | + if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) { |
|
119 | 119 | $this->expires = $this::EOL_NEVER_EXPIRES; |
120 | 120 | } |
121 | - elseif($expires > $now){ |
|
121 | + elseif ($expires > $now) { |
|
122 | 122 | $this->expires = $expires; |
123 | 123 | } |
124 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
124 | + elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) { |
|
125 | 125 | $this->expires = $now + $expires; |
126 | 126 | } |
127 | 127 |
@@ -78,11 +78,9 @@ |
||
78 | 78 | |
79 | 79 | if(!$data || !is_array($data)){ |
80 | 80 | throw new ProviderException('unable to parse token response'); |
81 | - } |
|
82 | - elseif(isset($data['error'])){ |
|
81 | + } elseif(isset($data['error'])){ |
|
83 | 82 | throw new ProviderException('error retrieving access token: '.$data['error']); |
84 | - } |
|
85 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
83 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
86 | 84 | throw new ProviderException('invalid token'); |
87 | 85 | } |
88 | 86 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | implode, in_array, is_array, parse_str, parse_url, random_bytes, strtoupper; |
22 | 22 | use function chillerlan\HTTP\Psr7\{build_http_query, decompress_content, merge_query, r_rawurlencode}; |
23 | 23 | |
24 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
24 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @var string |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ->withHeader('Accept-Encoding', 'identity') |
66 | 66 | ; |
67 | 67 | |
68 | - foreach($this->authHeaders as $header => $value){ |
|
68 | + foreach ($this->authHeaders as $header => $value) { |
|
69 | 69 | $request = $request->withAddedHeader($header, $value); |
70 | 70 | } |
71 | 71 | |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
83 | 83 | parse_str(decompress_content($response), $data); |
84 | 84 | |
85 | - if(!$data || !is_array($data)){ |
|
85 | + if (!$data || !is_array($data)) { |
|
86 | 86 | throw new ProviderException('unable to parse token response'); |
87 | 87 | } |
88 | - elseif(isset($data['error'])){ |
|
88 | + elseif (isset($data['error'])) { |
|
89 | 89 | throw new ProviderException('error retrieving access token: '.$data['error']); |
90 | 90 | } |
91 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
91 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
92 | 92 | throw new ProviderException('invalid token'); |
93 | 93 | } |
94 | 94 | |
95 | - if($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')){ |
|
95 | + if ($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')) { |
|
96 | 96 | throw new ProviderException('oauth callback unconfirmed'); |
97 | 97 | } |
98 | 98 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
139 | 139 | $parseURL = parse_url($url); |
140 | 140 | |
141 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
141 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
142 | 142 | throw new ProviderException('getSignature: invalid url'); |
143 | 143 | } |
144 | 144 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | $signatureParams = array_merge($query, $params); |
148 | 148 | |
149 | - if(isset($signatureParams['oauth_signature'])){ |
|
149 | + if (isset($signatureParams['oauth_signature'])) { |
|
150 | 150 | unset($signatureParams['oauth_signature']); |
151 | 151 | } |
152 | 152 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $token->accessTokenSecret |
205 | 205 | ); |
206 | 206 | |
207 | - if(isset($query['oauth_session_handle'])){ |
|
207 | + if (isset($query['oauth_session_handle'])) { |
|
208 | 208 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
209 | 209 | } |
210 | 210 |
@@ -296,8 +296,7 @@ |
||
296 | 296 | // @todo: content type support |
297 | 297 | if($contentType === 'application/x-www-form-urlencoded'){ |
298 | 298 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
299 | - } |
|
300 | - elseif($contentType === 'application/json'){ |
|
299 | + } elseif($contentType === 'application/json'){ |
|
301 | 300 | $body = $this->streamFactory->createStream(json_encode($body)); |
302 | 301 | } |
303 | 302 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @property string $serviceName |
43 | 43 | * @property string $userRevokeURL |
44 | 44 | */ |
45 | -abstract class OAuthProvider implements OAuthInterface{ |
|
45 | +abstract class OAuthProvider implements OAuthInterface { |
|
46 | 46 | use LoggerAwareTrait; |
47 | 47 | |
48 | 48 | protected const ALLOWED_PROPERTIES = [ |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
151 | 151 | */ |
152 | - public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){ |
|
152 | + public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) { |
|
153 | 153 | $this->http = $http; |
154 | 154 | $this->storage = $storage; |
155 | 155 | $this->options = $options; |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | |
162 | 162 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
163 | 163 | |
164 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
164 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
165 | 165 | $this->endpoints = new $this->endpointMap; |
166 | 166 | |
167 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
167 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
168 | 168 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
169 | 169 | } |
170 | 170 | |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return mixed|null |
179 | 179 | */ |
180 | - public function __get(string $name){ |
|
180 | + public function __get(string $name) { |
|
181 | 181 | |
182 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
182 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
183 | 183 | return $this->{$name}; |
184 | 184 | } |
185 | 185 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | */ |
249 | 249 | public function __call(string $name, array $arguments):ResponseInterface{ |
250 | 250 | |
251 | - if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){ |
|
251 | + if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) { |
|
252 | 252 | throw new ApiClientException('MagicAPI not available'); |
253 | 253 | } |
254 | 254 | |
255 | - if(!$this->endpoints->__isset($name)){ |
|
255 | + if (!$this->endpoints->__isset($name)) { |
|
256 | 256 | throw new ApiClientException('endpoint not found: "'.$name.'"'); |
257 | 257 | } |
258 | 258 | |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | $path_elements = $m['path_elements'] ?? []; |
266 | 266 | $params_in_url = count($path_elements); |
267 | 267 | $params = $arguments[$params_in_url] ?? []; |
268 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
268 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
269 | 269 | |
270 | - if($params_in_url > 0){ |
|
270 | + if ($params_in_url > 0) { |
|
271 | 271 | |
272 | - if(count($urlparams) < $params_in_url){ |
|
272 | + if (count($urlparams) < $params_in_url) { |
|
273 | 273 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
274 | 274 | } |
275 | 275 | |
276 | 276 | $endpoint = sprintf($endpoint, ...$urlparams); |
277 | 277 | } |
278 | 278 | |
279 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
279 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
280 | 280 | $body = $arguments[$params_in_url + 1] ?? $params; |
281 | 281 | |
282 | - if($params === $body){ |
|
282 | + if ($params === $body) { |
|
283 | 283 | $params = []; |
284 | 284 | } |
285 | 285 | |
@@ -329,24 +329,24 @@ discard block |
||
329 | 329 | $request = $this->requestFactory |
330 | 330 | ->createRequest($method ?? 'GET', merge_query($this->apiURL.$path, $params ?? [])); |
331 | 331 | |
332 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
332 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
333 | 333 | $request = $request->withAddedHeader($header, $value); |
334 | 334 | } |
335 | 335 | |
336 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
336 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
337 | 337 | $contentType = strtolower($request->getHeaderLine('content-type')); |
338 | 338 | |
339 | 339 | // @todo: content type support |
340 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
340 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
341 | 341 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
342 | 342 | } |
343 | - elseif($contentType === 'application/json'){ |
|
343 | + elseif ($contentType === 'application/json') { |
|
344 | 344 | $body = $this->streamFactory->createStream(json_encode($body)); |
345 | 345 | } |
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', $body->getSize()) |
@@ -364,11 +364,11 @@ discard block |
||
364 | 364 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
365 | 365 | |
366 | 366 | // get authorization only if we request the provider API |
367 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
367 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
368 | 368 | $token = $this->storage->getAccessToken($this->serviceName); |
369 | 369 | |
370 | 370 | // attempt to refresh an expired token |
371 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
371 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
372 | 372 | $token = $this->refreshAccessToken($token); |
373 | 373 | } |
374 | 374 |
@@ -76,8 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
78 | 78 | $_SESSION[$this->sessionVar][$service] = $data; |
79 | - } |
|
80 | - else{ |
|
79 | + } else{ |
|
81 | 80 | $_SESSION[$this->sessionVar] = [$service => $data]; |
82 | 81 | } |
83 | 82 | |
@@ -146,8 +145,7 @@ discard block |
||
146 | 145 | |
147 | 146 | if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
148 | 147 | $_SESSION[$this->stateVar][$service] = $state; |
149 | - } |
|
150 | - else{ |
|
148 | + } else{ |
|
151 | 149 | $_SESSION[$this->stateVar] = [$service => $state]; |
152 | 150 | } |
153 | 151 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | use const PHP_SESSION_NONE; |
21 | 21 | |
22 | -class SessionStorage extends OAuthStorageAbstract{ |
|
22 | +class SessionStorage extends OAuthStorageAbstract { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @var string |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
38 | 38 | */ |
39 | - public function __construct(SettingsContainerInterface $options = null){ |
|
39 | + public function __construct(SettingsContainerInterface $options = null) { |
|
40 | 40 | parent::__construct($options); |
41 | 41 | |
42 | 42 | $this->sessionVar = $this->options->sessionTokenVar; |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | |
45 | 45 | // Determine if the session has started. |
46 | 46 | // @link http://stackoverflow.com/a/18542272/1470961 |
47 | - if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){ |
|
47 | + if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) { |
|
48 | 48 | session_start(); |
49 | 49 | } |
50 | 50 | |
51 | - if(!isset($_SESSION[$this->sessionVar])){ |
|
51 | + if (!isset($_SESSION[$this->sessionVar])) { |
|
52 | 52 | $_SESSION[$this->sessionVar] = []; |
53 | 53 | } |
54 | 54 | |
55 | - if(!isset($_SESSION[$this->stateVar])){ |
|
55 | + if (!isset($_SESSION[$this->stateVar])) { |
|
56 | 56 | $_SESSION[$this->stateVar] = []; |
57 | 57 | } |
58 | 58 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @codeCoverageIgnore |
65 | 65 | */ |
66 | - public function __destruct(){ |
|
67 | - if($this->options->sessionStart){ |
|
66 | + public function __destruct() { |
|
67 | + if ($this->options->sessionStart) { |
|
68 | 68 | session_write_close(); |
69 | 69 | } |
70 | 70 | } |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
79 | 79 | $data = $this->toStorage($token); |
80 | 80 | |
81 | - if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
|
81 | + if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) { |
|
82 | 82 | $_SESSION[$this->sessionVar][$service] = $data; |
83 | 83 | } |
84 | - else{ |
|
84 | + else { |
|
85 | 85 | $_SESSION[$this->sessionVar] = [$service => $data]; |
86 | 86 | } |
87 | 87 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function getAccessToken(string $service):AccessToken{ |
98 | 98 | |
99 | - if($this->hasAccessToken($service)){ |
|
99 | + if ($this->hasAccessToken($service)) { |
|
100 | 100 | return $this->fromStorage($_SESSION[$this->sessionVar][$service]); |
101 | 101 | } |
102 | 102 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
121 | 121 | |
122 | - if(array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
122 | + if (array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
123 | 123 | unset($_SESSION[$this->sessionVar][$service]); |
124 | 124 | } |
125 | 125 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function clearAllAccessTokens():OAuthStorageInterface{ |
133 | 133 | |
134 | - foreach(array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
134 | + foreach (array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
135 | 135 | unset($_SESSION[$this->sessionVar][$service]); |
136 | 136 | } |
137 | 137 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public function storeCSRFState(string $service, string $state):OAuthStorageInterface{ |
150 | 150 | |
151 | - if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
|
151 | + if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) { |
|
152 | 152 | $_SESSION[$this->stateVar][$service] = $state; |
153 | 153 | } |
154 | - else{ |
|
154 | + else { |
|
155 | 155 | $_SESSION[$this->stateVar] = [$service => $state]; |
156 | 156 | } |
157 | 157 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function getCSRFState(string $service):string{ |
168 | 168 | |
169 | - if($this->hasCSRFState($service)){ |
|
169 | + if ($this->hasCSRFState($service)) { |
|
170 | 170 | return $_SESSION[$this->stateVar][$service]; |
171 | 171 | } |
172 | 172 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
191 | 191 | |
192 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
192 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
193 | 193 | unset($_SESSION[$this->stateVar][$service]); |
194 | 194 | } |
195 | 195 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | use const PHP_QUERY_RFC1738; |
24 | 24 | |
25 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
25 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @var int |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | public function getAuthURL(array $params = null, array $scopes = null):UriInterface{ |
54 | 54 | $params = $params ?? []; |
55 | 55 | |
56 | - if(isset($params['client_secret'])){ |
|
56 | + if (isset($params['client_secret'])) { |
|
57 | 57 | unset($params['client_secret']); |
58 | 58 | } |
59 | 59 | |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | 'type' => 'web_server', |
65 | 65 | ]); |
66 | 66 | |
67 | - if(!empty($scopes)){ |
|
67 | + if (!empty($scopes)) { |
|
68 | 68 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
69 | 69 | } |
70 | 70 | |
71 | - if($this instanceof CSRFToken){ |
|
71 | + if ($this instanceof CSRFToken) { |
|
72 | 72 | $params = $this->setState($params); |
73 | 73 | } |
74 | 74 | |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | protected function parseTokenResponse(ResponseInterface $response):AccessToken{ |
85 | 85 | $data = json_decode(decompress_content($response), true); // silly amazon... |
86 | 86 | |
87 | - if(!is_array($data)){ |
|
87 | + if (!is_array($data)) { |
|
88 | 88 | throw new ProviderException('unable to parse token response'); |
89 | 89 | } |
90 | 90 | |
91 | - foreach(['error_description', 'error'] as $field){ |
|
91 | + foreach (['error_description', 'error'] as $field) { |
|
92 | 92 | |
93 | - if(isset($data[$field])){ |
|
93 | + if (isset($data[$field])) { |
|
94 | 94 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
95 | 95 | } |
96 | 96 | |
97 | 97 | } |
98 | 98 | |
99 | - if(!isset($data['access_token'])){ |
|
99 | + if (!isset($data['access_token'])) { |
|
100 | 100 | throw new ProviderException('token missing'); |
101 | 101 | } |
102 | 102 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getAccessToken(string $code, string $state = null):AccessToken{ |
124 | 124 | |
125 | - if($this instanceof CSRFToken){ |
|
125 | + if ($this instanceof CSRFToken) { |
|
126 | 126 | $this->checkState($state); |
127 | 127 | } |
128 | 128 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | ->withHeader('Accept-Encoding', 'identity') |
141 | 141 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))); |
142 | 142 | |
143 | - foreach($this->authHeaders as $header => $value){ |
|
143 | + foreach ($this->authHeaders as $header => $value) { |
|
144 | 144 | $request = $request->withHeader($header, $value); |
145 | 145 | } |
146 | 146 | |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{ |
162 | 162 | |
163 | - if(array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)){ |
|
163 | + if (array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)) { |
|
164 | 164 | $request = $request->withHeader('Authorization', OAuth2Interface::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken); |
165 | 165 | } |
166 | - elseif(array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
166 | + elseif (array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)) { |
|
167 | 167 | $uri = merge_query((string)$request->getUri(), [OAuth2Interface::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]); |
168 | 168 | |
169 | 169 | $request = $request->withUri($this->uriFactory->createUri($uri)); |
170 | 170 | } |
171 | - else{ |
|
171 | + else { |
|
172 | 172 | throw new ProviderException('invalid auth type'); |
173 | 173 | } |
174 | 174 | |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function getClientCredentialsToken(array $scopes = null):AccessToken{ |
185 | 185 | |
186 | - if(!$this instanceof ClientCredentials){ |
|
186 | + if (!$this instanceof ClientCredentials) { |
|
187 | 187 | throw new ProviderException('client credentials token not supported'); |
188 | 188 | } |
189 | 189 | |
190 | 190 | $params = ['grant_type' => 'client_credentials']; |
191 | 191 | |
192 | - if($scopes !== null){ |
|
192 | + if ($scopes !== null) { |
|
193 | 193 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
194 | 194 | } |
195 | 195 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | ->withBody($this->streamFactory->createStream(http_build_query($params, '', '&', PHP_QUERY_RFC1738))) |
202 | 202 | ; |
203 | 203 | |
204 | - foreach($this->authHeaders as $header => $value){ |
|
204 | + foreach ($this->authHeaders as $header => $value) { |
|
205 | 205 | $request = $request->withAddedHeader($header, $value); |
206 | 206 | } |
207 | 207 | |
@@ -220,19 +220,19 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function refreshAccessToken(AccessToken $token = null):AccessToken{ |
222 | 222 | |
223 | - if(!$this instanceof TokenRefresh){ |
|
223 | + if (!$this instanceof TokenRefresh) { |
|
224 | 224 | throw new ProviderException('token refresh not supported'); |
225 | 225 | } |
226 | 226 | |
227 | - if($token === null){ |
|
227 | + if ($token === null) { |
|
228 | 228 | $token = $this->storage->getAccessToken($this->serviceName); |
229 | 229 | } |
230 | 230 | |
231 | 231 | $refreshToken = $token->refreshToken; |
232 | 232 | |
233 | - if(empty($refreshToken)){ |
|
233 | + if (empty($refreshToken)) { |
|
234 | 234 | |
235 | - if(!$this instanceof AccessTokenForRefresh){ |
|
235 | + if (!$this instanceof AccessTokenForRefresh) { |
|
236 | 236 | throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))); |
237 | 237 | } |
238 | 238 | |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))) |
255 | 255 | ; |
256 | 256 | |
257 | - foreach($this->authHeaders as $header => $value){ |
|
257 | + foreach ($this->authHeaders as $header => $value) { |
|
258 | 258 | $request = $request->withAddedHeader($header, $value); |
259 | 259 | } |
260 | 260 | |
261 | 261 | $newToken = $this->parseTokenResponse($this->http->sendRequest($request)); |
262 | 262 | |
263 | - if(empty($newToken->refreshToken)){ |
|
263 | + if (empty($newToken->refreshToken)) { |
|
264 | 264 | $newToken->refreshToken = $refreshToken; |
265 | 265 | } |
266 | 266 | |
@@ -277,13 +277,13 @@ discard block |
||
277 | 277 | */ |
278 | 278 | protected function checkState(string $state = null):void{ |
279 | 279 | |
280 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
280 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
281 | 281 | throw new ProviderException('invalid state for '.$this->serviceName); |
282 | 282 | } |
283 | 283 | |
284 | 284 | $knownState = $this->storage->getCSRFState($this->serviceName); |
285 | 285 | |
286 | - if(!hash_equals($knownState, $state)){ |
|
286 | + if (!hash_equals($knownState, $state)) { |
|
287 | 287 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
288 | 288 | } |
289 | 289 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | protected function setState(array $params):array{ |
298 | 298 | |
299 | - if(!isset($params['state'])){ |
|
299 | + if (!isset($params['state'])) { |
|
300 | 300 | $params['state'] = sha1(random_bytes(256)); |
301 | 301 | } |
302 | 302 |
@@ -162,13 +162,11 @@ |
||
162 | 162 | |
163 | 163 | if(array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)){ |
164 | 164 | $request = $request->withHeader('Authorization', OAuth2Interface::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken); |
165 | - } |
|
166 | - elseif(array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
165 | + } elseif(array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
167 | 166 | $uri = merge_query((string)$request->getUri(), [OAuth2Interface::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]); |
168 | 167 | |
169 | 168 | $request = $request->withUri($this->uriFactory->createUri($uri)); |
170 | - } |
|
171 | - else{ |
|
169 | + } else{ |
|
172 | 170 | throw new ProviderException('invalid auth type'); |
173 | 171 | } |
174 | 172 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | use Psr\Log\{LoggerAwareTrait, LoggerInterface, NullLogger}; |
18 | 18 | |
19 | -abstract class OAuthStorageAbstract implements OAuthStorageInterface{ |
|
19 | +abstract class OAuthStorageAbstract implements OAuthStorageInterface { |
|
20 | 20 | use LoggerAwareTrait; |
21 | 21 | |
22 | 22 | /** |
@@ -30,7 +30,7 @@ discard block |
||
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 | |
36 | 36 | $this->setLogger($logger ?? new NullLogger); |
@@ -15,7 +15,7 @@ |
||
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | use Psr\Log\LoggerAwareInterface; |
17 | 17 | |
18 | -interface OAuthStorageInterface extends LoggerAwareInterface{ |
|
18 | +interface OAuthStorageInterface extends LoggerAwareInterface { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param string $service |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | use function array_keys, array_key_exists; |
18 | 18 | |
19 | -class MemoryStorage extends OAuthStorageAbstract{ |
|
19 | +class MemoryStorage extends OAuthStorageAbstract { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var array |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function getAccessToken(string $service):AccessToken{ |
50 | 50 | |
51 | - if($this->hasAccessToken($service)){ |
|
51 | + if ($this->hasAccessToken($service)) { |
|
52 | 52 | return $this->tokens[$service]; |
53 | 53 | } |
54 | 54 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
73 | 73 | |
74 | - if(array_key_exists($service, $this->tokens)){ |
|
74 | + if (array_key_exists($service, $this->tokens)) { |
|
75 | 75 | unset($this->tokens[$service]); |
76 | 76 | } |
77 | 77 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function clearAllAccessTokens():OAuthStorageInterface{ |
85 | 85 | |
86 | - foreach(array_keys($this->tokens) as $service){ |
|
86 | + foreach (array_keys($this->tokens) as $service) { |
|
87 | 87 | unset($this->tokens[$service]); |
88 | 88 | } |
89 | 89 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getCSRFState(string $service):string{ |
114 | 114 | |
115 | - if($this->hasCSRFState($service)){ |
|
115 | + if ($this->hasCSRFState($service)) { |
|
116 | 116 | return $this->states[$service]; |
117 | 117 | } |
118 | 118 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
137 | 137 | |
138 | - if(array_key_exists($service, $this->states)){ |
|
138 | + if (array_key_exists($service, $this->states)) { |
|
139 | 139 | unset($this->states[$service]); |
140 | 140 | } |
141 | 141 |