@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use Psr\Http\Message\UriInterface; |
16 | 16 | |
17 | -interface OAuth2Interface extends OAuthInterface{ |
|
17 | +interface OAuth2Interface extends OAuthInterface { |
|
18 | 18 | |
19 | 19 | const HEADER_OAUTH = 0; |
20 | 20 | const HEADER_BEARER = 1; |
@@ -36,6 +36,6 @@ |
||
36 | 36 | * @property bool $ssl_verifypeer |
37 | 37 | * @property string $curlHandle |
38 | 38 | */ |
39 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
39 | +class OAuthOptions extends SettingsContainerAbstract { |
|
40 | 40 | use OAuthOptionsTrait, HTTPOptionsTrait; |
41 | 41 | } |
@@ -123,11 +123,9 @@ |
||
123 | 123 | |
124 | 124 | if($expires === 0 || $expires === self::EOL_NEVER_EXPIRES){ |
125 | 125 | $this->expires = self::EOL_NEVER_EXPIRES; |
126 | - } |
|
127 | - elseif($expires > $now){ |
|
126 | + } elseif($expires > $now){ |
|
128 | 127 | $this->expires = $expires; |
129 | - } |
|
130 | - elseif($expires > 0 && $expires < self::EXPIRY_MAX){ |
|
128 | + } elseif($expires > 0 && $expires < self::EXPIRY_MAX){ |
|
131 | 129 | $this->expires = $now + $expires; |
132 | 130 | } |
133 | 131 |
@@ -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. |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @param iterable|null $properties |
85 | 85 | */ |
86 | - public function __construct(iterable $properties = null){ |
|
86 | + public function __construct(iterable $properties = null) { |
|
87 | 87 | parent::__construct($properties); |
88 | 88 | |
89 | 89 | $this->setExpiry($this->expires); |
@@ -108,19 +108,19 @@ discard block |
||
108 | 108 | public function setExpiry(int $expires = null):AccessToken{ |
109 | 109 | $now = \time(); |
110 | 110 | |
111 | - if($expires!== null){ |
|
111 | + if ($expires !== null) { |
|
112 | 112 | $expires = \intval($expires); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $this->expires = self::EOL_UNKNOWN; |
116 | 116 | |
117 | - if($expires === 0 || $expires === self::EOL_NEVER_EXPIRES){ |
|
117 | + if ($expires === 0 || $expires === self::EOL_NEVER_EXPIRES) { |
|
118 | 118 | $this->expires = self::EOL_NEVER_EXPIRES; |
119 | 119 | } |
120 | - elseif($expires > $now){ |
|
120 | + elseif ($expires > $now) { |
|
121 | 121 | $this->expires = $expires; |
122 | 122 | } |
123 | - elseif($expires > 0 && $expires < self::EXPIRY_MAX){ |
|
123 | + elseif ($expires > 0 && $expires < self::EXPIRY_MAX) { |
|
124 | 124 | $this->expires = $now + $expires; |
125 | 125 | } |
126 | 126 |
@@ -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 | |
36 | 36 | $this->setLogger($logger ?? new NullLogger); |
@@ -34,7 +34,7 @@ |
||
34 | 34 | ]; |
35 | 35 | |
36 | 36 | /** @var \chillerlan\Settings\SettingsContainerInterface $options */ |
37 | -$options = new class($options_arr) extends OAuthOptions{ |
|
37 | +$options = new class($options_arr) extends OAuthOptions { |
|
38 | 38 | protected $sleep; // testHTTPClient |
39 | 39 | }; |
40 | 40 |
@@ -306,8 +306,7 @@ |
||
306 | 306 | // @todo: content type support |
307 | 307 | if($contentType === 'application/x-www-form-urlencoded'){ |
308 | 308 | $body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)); |
309 | - } |
|
310 | - elseif($contentType === 'application/json'){ |
|
309 | + } elseif($contentType === 'application/json'){ |
|
311 | 310 | $body = $this->streamFactory->createStream(\json_encode($body)); |
312 | 311 | } |
313 | 312 |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
142 | 142 | */ |
143 | - public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){ |
|
143 | + public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) { |
|
144 | 144 | $this->http = $http; |
145 | 145 | $this->storage = $storage; |
146 | 146 | $this->options = $options; |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | |
153 | 153 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
154 | 154 | |
155 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)){ |
|
155 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)) { |
|
156 | 156 | $this->endpoints = new $this->endpointMap; |
157 | 157 | |
158 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
158 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
159 | 159 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
160 | 160 | } |
161 | 161 | |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return mixed|null |
170 | 170 | */ |
171 | - public function __get(string $name){ |
|
171 | + public function __get(string $name) { |
|
172 | 172 | |
173 | - if(\in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
173 | + if (\in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
174 | 174 | return $this->{$name}; |
175 | 175 | } |
176 | 176 | |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function __call(string $name, array $arguments):ResponseInterface{ |
229 | 229 | |
230 | - if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){ |
|
230 | + if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) { |
|
231 | 231 | throw new ApiClientException('MagicAPI not available'); |
232 | 232 | } |
233 | 233 | |
234 | - if(!$this->endpoints->__isset($name)){ |
|
234 | + if (!$this->endpoints->__isset($name)) { |
|
235 | 235 | throw new ApiClientException('endpoint not found: "'.$name.'"'); |
236 | 236 | } |
237 | 237 | |
@@ -244,21 +244,21 @@ discard block |
||
244 | 244 | $path_elements = $m['path_elements'] ?? []; |
245 | 245 | $params_in_url = \count($path_elements); |
246 | 246 | $params = $arguments[$params_in_url] ?? []; |
247 | - $urlparams = \array_slice($arguments,0 , $params_in_url); |
|
247 | + $urlparams = \array_slice($arguments, 0, $params_in_url); |
|
248 | 248 | |
249 | - if($params_in_url > 0){ |
|
249 | + if ($params_in_url > 0) { |
|
250 | 250 | |
251 | - if(\count($urlparams) < $params_in_url){ |
|
251 | + if (\count($urlparams) < $params_in_url) { |
|
252 | 252 | throw new APIClientException('too few URL params, required: '.\implode(', ', $path_elements)); |
253 | 253 | } |
254 | 254 | |
255 | 255 | $endpoint = \sprintf($endpoint, ...$urlparams); |
256 | 256 | } |
257 | 257 | |
258 | - if(\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
258 | + if (\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
259 | 259 | $body = $arguments[$params_in_url + 1] ?? $params; |
260 | 260 | |
261 | - if($params === $body){ |
|
261 | + if ($params === $body) { |
|
262 | 262 | $params = []; |
263 | 263 | } |
264 | 264 | |
@@ -308,24 +308,24 @@ discard block |
||
308 | 308 | $request = $this->requestFactory |
309 | 309 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? [])); |
310 | 310 | |
311 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
311 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
312 | 312 | $request = $request->withAddedHeader($header, $value); |
313 | 313 | } |
314 | 314 | |
315 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
315 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
316 | 316 | $contentType = \strtolower($request->getHeaderLine('content-type')); |
317 | 317 | |
318 | 318 | // @todo: content type support |
319 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
319 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
320 | 320 | $body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)); |
321 | 321 | } |
322 | - elseif($contentType === 'application/json'){ |
|
322 | + elseif ($contentType === 'application/json') { |
|
323 | 323 | $body = $this->streamFactory->createStream(\json_encode($body)); |
324 | 324 | } |
325 | 325 | |
326 | 326 | } |
327 | 327 | |
328 | - if($body instanceof StreamInterface){ |
|
328 | + if ($body instanceof StreamInterface) { |
|
329 | 329 | $request = $request |
330 | 330 | ->withBody($body) |
331 | 331 | ->withHeader('Content-length', $body->getSize()) |
@@ -343,11 +343,11 @@ discard block |
||
343 | 343 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
344 | 344 | |
345 | 345 | // get authorization only if we request the provider API |
346 | - if(\strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
346 | + if (\strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
347 | 347 | $token = $this->storage->getAccessToken($this->serviceName); |
348 | 348 | |
349 | 349 | // attempt to refresh an expired token |
350 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
350 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
351 | 351 | $token = $this->refreshAccessToken($token); |
352 | 352 | } |
353 | 353 |
@@ -167,13 +167,11 @@ |
||
167 | 167 | |
168 | 168 | if(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)){ |
169 | 169 | $request = $request->withHeader('Authorization', OAuth2Interface::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken); |
170 | - } |
|
171 | - elseif(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
170 | + } elseif(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
172 | 171 | $uri = Psr7\merge_query((string)$request->getUri(), [OAuth2Interface::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]); |
173 | 172 | |
174 | 173 | $request = $request->withUri($this->uriFactory->createUri($uri)); |
175 | - } |
|
176 | - else{ |
|
174 | + } else{ |
|
177 | 175 | throw new ProviderException('invalid auth type'); |
178 | 176 | } |
179 | 177 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | use chillerlan\HTTP\Psr7; |
18 | 18 | use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface}; |
19 | 19 | |
20 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
20 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var int |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | public function getAuthURL(array $params = null, array $scopes = null):UriInterface{ |
49 | 49 | $params = $params ?? []; |
50 | 50 | |
51 | - if(isset($params['client_secret'])){ |
|
51 | + if (isset($params['client_secret'])) { |
|
52 | 52 | unset($params['client_secret']); |
53 | 53 | } |
54 | 54 | |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | 'type' => 'web_server', |
60 | 60 | ]); |
61 | 61 | |
62 | - if(!empty($scopes)){ |
|
62 | + if (!empty($scopes)) { |
|
63 | 63 | $params['scope'] = \implode($this->scopesDelimiter, $scopes); |
64 | 64 | } |
65 | 65 | |
66 | - if($this instanceof CSRFToken){ |
|
66 | + if ($this instanceof CSRFToken) { |
|
67 | 67 | $params = $this->setState($params); |
68 | 68 | } |
69 | 69 | |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | protected function parseTokenResponse(ResponseInterface $response):AccessToken{ |
80 | 80 | $data = \json_decode(Psr7\decompress_content($response), true); // silly amazon... |
81 | 81 | |
82 | - if(!\is_array($data)){ |
|
82 | + if (!\is_array($data)) { |
|
83 | 83 | throw new ProviderException('unable to parse token response'); |
84 | 84 | } |
85 | 85 | |
86 | - foreach(['error_description', 'error'] as $field){ |
|
86 | + foreach (['error_description', 'error'] as $field) { |
|
87 | 87 | |
88 | - if(isset($data[$field])){ |
|
88 | + if (isset($data[$field])) { |
|
89 | 89 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
90 | 90 | } |
91 | 91 | |
92 | 92 | } |
93 | 93 | |
94 | - if(!isset($data['access_token'])){ |
|
94 | + if (!isset($data['access_token'])) { |
|
95 | 95 | throw new ProviderException('token missing'); |
96 | 96 | } |
97 | 97 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function getAccessToken(string $code, string $state = null):AccessToken{ |
119 | 119 | |
120 | - if($this instanceof CSRFToken){ |
|
120 | + if ($this instanceof CSRFToken) { |
|
121 | 121 | $this->checkState($state); |
122 | 122 | } |
123 | 123 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ->withHeader('Accept-Encoding', 'identity') |
136 | 136 | ->withBody($this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738))); |
137 | 137 | |
138 | - foreach($this->authHeaders as $header => $value){ |
|
138 | + foreach ($this->authHeaders as $header => $value) { |
|
139 | 139 | $request = $request->withHeader($header, $value); |
140 | 140 | } |
141 | 141 | |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{ |
157 | 157 | |
158 | - if(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)){ |
|
158 | + if (\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)) { |
|
159 | 159 | $request = $request->withHeader('Authorization', OAuth2Interface::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken); |
160 | 160 | } |
161 | - elseif(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
161 | + elseif (\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)) { |
|
162 | 162 | $uri = Psr7\merge_query((string)$request->getUri(), [OAuth2Interface::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]); |
163 | 163 | |
164 | 164 | $request = $request->withUri($this->uriFactory->createUri($uri)); |
165 | 165 | } |
166 | - else{ |
|
166 | + else { |
|
167 | 167 | throw new ProviderException('invalid auth type'); |
168 | 168 | } |
169 | 169 | |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function getClientCredentialsToken(array $scopes = null):AccessToken{ |
180 | 180 | |
181 | - if(!$this instanceof ClientCredentials){ |
|
181 | + if (!$this instanceof ClientCredentials) { |
|
182 | 182 | throw new ProviderException('client credentials token not supported'); |
183 | 183 | } |
184 | 184 | |
185 | 185 | $params = ['grant_type' => 'client_credentials']; |
186 | 186 | |
187 | - if($scopes !== null){ |
|
187 | + if ($scopes !== null) { |
|
188 | 188 | $params['scope'] = \implode($this->scopesDelimiter, $scopes); |
189 | 189 | } |
190 | 190 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | ->withBody($this->streamFactory->createStream(\http_build_query($params, '', '&', \PHP_QUERY_RFC1738))) |
197 | 197 | ; |
198 | 198 | |
199 | - foreach($this->authHeaders as $header => $value){ |
|
199 | + foreach ($this->authHeaders as $header => $value) { |
|
200 | 200 | $request = $request->withAddedHeader($header, $value); |
201 | 201 | } |
202 | 202 | |
@@ -215,19 +215,19 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function refreshAccessToken(AccessToken $token = null):AccessToken{ |
217 | 217 | |
218 | - if(!$this instanceof TokenRefresh){ |
|
218 | + if (!$this instanceof TokenRefresh) { |
|
219 | 219 | throw new ProviderException('token refresh not supported'); |
220 | 220 | } |
221 | 221 | |
222 | - if($token === null){ |
|
222 | + if ($token === null) { |
|
223 | 223 | $token = $this->storage->getAccessToken($this->serviceName); |
224 | 224 | } |
225 | 225 | |
226 | 226 | $refreshToken = $token->refreshToken; |
227 | 227 | |
228 | - if(empty($refreshToken)){ |
|
228 | + if (empty($refreshToken)) { |
|
229 | 229 | |
230 | - if(!$this instanceof AccessTokenForRefresh){ |
|
230 | + if (!$this instanceof AccessTokenForRefresh) { |
|
231 | 231 | throw new ProviderException(\sprintf('no refresh token available, token expired [%s]', \date('Y-m-d h:i:s A', $token->expires))); |
232 | 232 | } |
233 | 233 | |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | ->withBody($this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738))) |
250 | 250 | ; |
251 | 251 | |
252 | - foreach($this->authHeaders as $header => $value){ |
|
252 | + foreach ($this->authHeaders as $header => $value) { |
|
253 | 253 | $request = $request->withAddedHeader($header, $value); |
254 | 254 | } |
255 | 255 | |
256 | 256 | $newToken = $this->parseTokenResponse($this->http->sendRequest($request)); |
257 | 257 | |
258 | - if(empty($newToken->refreshToken)){ |
|
258 | + if (empty($newToken->refreshToken)) { |
|
259 | 259 | $newToken->refreshToken = $refreshToken; |
260 | 260 | } |
261 | 261 | |
@@ -272,13 +272,13 @@ discard block |
||
272 | 272 | */ |
273 | 273 | protected function checkState(string $state = null):void{ |
274 | 274 | |
275 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
275 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
276 | 276 | throw new ProviderException('invalid state for '.$this->serviceName); |
277 | 277 | } |
278 | 278 | |
279 | 279 | $knownState = $this->storage->getCSRFState($this->serviceName); |
280 | 280 | |
281 | - if(!\hash_equals($knownState, $state)){ |
|
281 | + if (!\hash_equals($knownState, $state)) { |
|
282 | 282 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
283 | 283 | } |
284 | 284 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | */ |
292 | 292 | protected function setState(array $params):array{ |
293 | 293 | |
294 | - if(!isset($params['state'])){ |
|
294 | + if (!isset($params['state'])) { |
|
295 | 295 | $params['state'] = \sha1(\random_bytes(256)); |
296 | 296 | } |
297 | 297 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | use DateTime; |
19 | 19 | use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface}; |
20 | 20 | |
21 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
21 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @var string |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | ->withHeader('Accept-Encoding', 'identity') |
63 | 63 | ; |
64 | 64 | |
65 | - foreach($this->authHeaders as $header => $value){ |
|
65 | + foreach ($this->authHeaders as $header => $value) { |
|
66 | 66 | $request = $request->withAddedHeader($header, $value); |
67 | 67 | } |
68 | 68 | |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
80 | 80 | \parse_str(Psr7\decompress_content($response), $data); |
81 | 81 | |
82 | - if(!$data || !\is_array($data)){ |
|
82 | + if (!$data || !\is_array($data)) { |
|
83 | 83 | throw new ProviderException('unable to parse token response'); |
84 | 84 | } |
85 | - elseif(isset($data['error'])){ |
|
85 | + elseif (isset($data['error'])) { |
|
86 | 86 | throw new ProviderException('error retrieving access token: '.$data['error']); |
87 | 87 | } |
88 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
88 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
89 | 89 | throw new ProviderException('invalid token'); |
90 | 90 | } |
91 | 91 | |
92 | - if($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')){ |
|
92 | + if ($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')) { |
|
93 | 93 | throw new ProviderException('oauth callback unconfirmed'); |
94 | 94 | } |
95 | 95 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
136 | 136 | $parseURL = \parse_url($url); |
137 | 137 | |
138 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !\in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
138 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !\in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
139 | 139 | throw new ProviderException('getSignature: invalid url'); |
140 | 140 | } |
141 | 141 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $signatureParams = \array_merge($query, $params); |
145 | 145 | |
146 | - if(isset($signatureParams['oauth_signature'])){ |
|
146 | + if (isset($signatureParams['oauth_signature'])) { |
|
147 | 147 | unset($signatureParams['oauth_signature']); |
148 | 148 | } |
149 | 149 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $token->accessTokenSecret |
202 | 202 | ); |
203 | 203 | |
204 | - if(isset($query['oauth_session_handle'])){ |
|
204 | + if (isset($query['oauth_session_handle'])) { |
|
205 | 205 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
206 | 206 | } |
207 | 207 |
@@ -81,11 +81,9 @@ |
||
81 | 81 | |
82 | 82 | if(!$data || !\is_array($data)){ |
83 | 83 | throw new ProviderException('unable to parse token response'); |
84 | - } |
|
85 | - elseif(isset($data['error'])){ |
|
84 | + } elseif(isset($data['error'])){ |
|
86 | 85 | throw new ProviderException('error retrieving access token: '.$data['error']); |
87 | - } |
|
88 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
86 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
89 | 87 | throw new ProviderException('invalid token'); |
90 | 88 | } |
91 | 89 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | |
18 | -class SessionStorage extends OAuthStorageAbstract{ |
|
18 | +class SessionStorage extends OAuthStorageAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var string |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
34 | 34 | */ |
35 | - public function __construct(SettingsContainerInterface $options = null){ |
|
35 | + public function __construct(SettingsContainerInterface $options = null) { |
|
36 | 36 | parent::__construct($options); |
37 | 37 | |
38 | 38 | $this->sessionVar = $this->options->sessionTokenVar; |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | |
41 | 41 | // Determine if the session has started. |
42 | 42 | // @link http://stackoverflow.com/a/18542272/1470961 |
43 | - if($this->options->sessionStart && !(\session_status() !== \PHP_SESSION_NONE)){ |
|
43 | + if ($this->options->sessionStart && !(\session_status() !== \PHP_SESSION_NONE)) { |
|
44 | 44 | \session_start(); |
45 | 45 | } |
46 | 46 | |
47 | - if(!isset($_SESSION[$this->sessionVar])){ |
|
47 | + if (!isset($_SESSION[$this->sessionVar])) { |
|
48 | 48 | $_SESSION[$this->sessionVar] = []; |
49 | 49 | } |
50 | 50 | |
51 | - if(!isset($_SESSION[$this->stateVar])){ |
|
51 | + if (!isset($_SESSION[$this->stateVar])) { |
|
52 | 52 | $_SESSION[$this->stateVar] = []; |
53 | 53 | } |
54 | 54 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @codeCoverageIgnore |
61 | 61 | */ |
62 | - public function __destruct(){ |
|
63 | - if($this->options->sessionStart){ |
|
62 | + public function __destruct() { |
|
63 | + if ($this->options->sessionStart) { |
|
64 | 64 | \session_write_close(); |
65 | 65 | } |
66 | 66 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
75 | 75 | $data = $this->toStorage($token); |
76 | 76 | |
77 | - if(isset($_SESSION[$this->sessionVar]) && \is_array($_SESSION[$this->sessionVar])){ |
|
77 | + if (isset($_SESSION[$this->sessionVar]) && \is_array($_SESSION[$this->sessionVar])) { |
|
78 | 78 | $_SESSION[$this->sessionVar][$service] = $data; |
79 | 79 | } |
80 | - else{ |
|
80 | + else { |
|
81 | 81 | $_SESSION[$this->sessionVar] = [$service => $data]; |
82 | 82 | } |
83 | 83 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function getAccessToken(string $service):AccessToken{ |
94 | 94 | |
95 | - if($this->hasAccessToken($service)){ |
|
95 | + if ($this->hasAccessToken($service)) { |
|
96 | 96 | return $this->fromStorage($_SESSION[$this->sessionVar][$service]); |
97 | 97 | } |
98 | 98 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
117 | 117 | |
118 | - if(\array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
118 | + if (\array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
119 | 119 | unset($_SESSION[$this->sessionVar][$service]); |
120 | 120 | } |
121 | 121 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function clearAllAccessTokens():OAuthStorageInterface{ |
129 | 129 | |
130 | - foreach(\array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
130 | + foreach (\array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
131 | 131 | unset($_SESSION[$this->sessionVar][$service]); |
132 | 132 | } |
133 | 133 | |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function storeCSRFState(string $service, string $state):OAuthStorageInterface{ |
146 | 146 | |
147 | - if(isset($_SESSION[$this->stateVar]) && \is_array($_SESSION[$this->stateVar])){ |
|
147 | + if (isset($_SESSION[$this->stateVar]) && \is_array($_SESSION[$this->stateVar])) { |
|
148 | 148 | $_SESSION[$this->stateVar][$service] = $state; |
149 | 149 | } |
150 | - else{ |
|
150 | + else { |
|
151 | 151 | $_SESSION[$this->stateVar] = [$service => $state]; |
152 | 152 | } |
153 | 153 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function getCSRFState(string $service):string{ |
164 | 164 | |
165 | - if($this->hasCSRFState($service)){ |
|
165 | + if ($this->hasCSRFState($service)) { |
|
166 | 166 | return $_SESSION[$this->stateVar][$service]; |
167 | 167 | } |
168 | 168 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
187 | 187 | |
188 | - if(\array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
188 | + if (\array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
189 | 189 | unset($_SESSION[$this->stateVar][$service]); |
190 | 190 | } |
191 | 191 |
@@ -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 |