@@ -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 |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | public function getAuthURL(array $params = null, array $scopes = null):UriInterface{ |
61 | 61 | $params = $params ?? []; |
62 | 62 | |
63 | - if(isset($params['client_secret'])){ |
|
63 | + if (isset($params['client_secret'])) { |
|
64 | 64 | unset($params['client_secret']); |
65 | 65 | } |
66 | 66 | |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | 'type' => 'web_server', |
72 | 72 | ]); |
73 | 73 | |
74 | - if(!empty($scopes)){ |
|
74 | + if (!empty($scopes)) { |
|
75 | 75 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
76 | 76 | } |
77 | 77 | |
78 | - if($this instanceof CSRFToken){ |
|
78 | + if ($this instanceof CSRFToken) { |
|
79 | 79 | $params = $this->setState($params); |
80 | 80 | } |
81 | 81 | |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | protected function parseTokenResponse(ResponseInterface $response):AccessToken{ |
92 | 92 | $data = json_decode(decompress_content($response), true); // silly amazon... |
93 | 93 | |
94 | - if(!is_array($data)){ |
|
94 | + if (!is_array($data)) { |
|
95 | 95 | throw new ProviderException('unable to parse token response'); |
96 | 96 | } |
97 | 97 | |
98 | - foreach(['error_description', 'error'] as $field){ |
|
98 | + foreach (['error_description', 'error'] as $field) { |
|
99 | 99 | |
100 | - if(isset($data[$field])){ |
|
100 | + if (isset($data[$field])) { |
|
101 | 101 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
102 | 102 | } |
103 | 103 | |
104 | 104 | } |
105 | 105 | |
106 | - if(!isset($data['access_token'])){ |
|
106 | + if (!isset($data['access_token'])) { |
|
107 | 107 | throw new ProviderException('token missing'); |
108 | 108 | } |
109 | 109 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function getAccessToken(string $code, string $state = null):AccessToken{ |
128 | 128 | |
129 | - if($this instanceof CSRFToken){ |
|
129 | + if ($this instanceof CSRFToken) { |
|
130 | 130 | $this->checkState($state); |
131 | 131 | } |
132 | 132 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | ->withHeader('Accept-Encoding', 'identity') |
145 | 145 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))); |
146 | 146 | |
147 | - foreach($this->authHeaders as $header => $value){ |
|
147 | + foreach ($this->authHeaders as $header => $value) { |
|
148 | 148 | $request = $request->withHeader($header, $value); |
149 | 149 | } |
150 | 150 | |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{ |
162 | 162 | |
163 | - if($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER){ |
|
163 | + if ($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER) { |
|
164 | 164 | return $request->withHeader('Authorization', $this->authMethodHeader.' '.$token->accessToken); |
165 | 165 | } |
166 | 166 | |
167 | - if($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY){ |
|
167 | + if ($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY) { |
|
168 | 168 | $uri = merge_query($request->getUri()->__toString(), [$this->authMethodQuery => $token->accessToken]); |
169 | 169 | |
170 | 170 | return $request->withUri($this->uriFactory->createUri($uri)); |
@@ -179,13 +179,13 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function getClientCredentialsToken(array $scopes = null):AccessToken{ |
181 | 181 | |
182 | - if(!$this instanceof ClientCredentials){ |
|
182 | + if (!$this instanceof ClientCredentials) { |
|
183 | 183 | throw new ProviderException('client credentials token not supported'); |
184 | 184 | } |
185 | 185 | |
186 | 186 | $params = ['grant_type' => 'client_credentials']; |
187 | 187 | |
188 | - if($scopes !== null){ |
|
188 | + if ($scopes !== null) { |
|
189 | 189 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
190 | 190 | } |
191 | 191 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | ->withBody($this->streamFactory->createStream(http_build_query($params, '', '&', PHP_QUERY_RFC1738))) |
198 | 198 | ; |
199 | 199 | |
200 | - foreach($this->authHeaders as $header => $value){ |
|
200 | + foreach ($this->authHeaders as $header => $value) { |
|
201 | 201 | $request = $request->withAddedHeader($header, $value); |
202 | 202 | } |
203 | 203 | |
@@ -214,17 +214,17 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function refreshAccessToken(AccessToken $token = null):AccessToken{ |
216 | 216 | |
217 | - if(!$this instanceof TokenRefresh){ |
|
217 | + if (!$this instanceof TokenRefresh) { |
|
218 | 218 | throw new ProviderException('token refresh not supported'); |
219 | 219 | } |
220 | 220 | |
221 | - if($token === null){ |
|
221 | + if ($token === null) { |
|
222 | 222 | $token = $this->storage->getAccessToken($this->serviceName); |
223 | 223 | } |
224 | 224 | |
225 | 225 | $refreshToken = $token->refreshToken; |
226 | 226 | |
227 | - if(empty($refreshToken)){ |
|
227 | + if (empty($refreshToken)) { |
|
228 | 228 | throw new ProviderException( |
229 | 229 | sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires)) |
230 | 230 | ); |
@@ -245,13 +245,13 @@ discard block |
||
245 | 245 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))) |
246 | 246 | ; |
247 | 247 | |
248 | - foreach($this->authHeaders as $header => $value){ |
|
248 | + foreach ($this->authHeaders as $header => $value) { |
|
249 | 249 | $request = $request->withAddedHeader($header, $value); |
250 | 250 | } |
251 | 251 | |
252 | 252 | $newToken = $this->parseTokenResponse($this->http->sendRequest($request)); |
253 | 253 | |
254 | - if(empty($newToken->refreshToken)){ |
|
254 | + if (empty($newToken->refreshToken)) { |
|
255 | 255 | $newToken->refreshToken = $refreshToken; |
256 | 256 | } |
257 | 257 | |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | */ |
269 | 269 | protected function checkState(string $state = null):void{ |
270 | 270 | |
271 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
271 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
272 | 272 | throw new ProviderException('invalid state for '.$this->serviceName); |
273 | 273 | } |
274 | 274 | |
275 | 275 | $knownState = $this->storage->getCSRFState($this->serviceName); |
276 | 276 | |
277 | - if(!hash_equals($knownState, $state)){ |
|
277 | + if (!hash_equals($knownState, $state)) { |
|
278 | 278 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
279 | 279 | } |
280 | 280 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | */ |
288 | 288 | protected function setState(array $params):array{ |
289 | 289 | |
290 | - if(!isset($params['state'])){ |
|
290 | + if (!isset($params['state'])) { |
|
291 | 291 | $params['state'] = sha1(random_bytes(256)); |
292 | 292 | } |
293 | 293 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @property string $serviceName |
40 | 40 | * @property string $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 = [ |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | OAuthStorageInterface $storage, |
152 | 152 | SettingsContainerInterface $options, |
153 | 153 | LoggerInterface $logger = null |
154 | - ){ |
|
154 | + ) { |
|
155 | 155 | $this->http = $http; |
156 | 156 | $this->storage = $storage; |
157 | 157 | $this->options = $options; |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | |
164 | 164 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
165 | 165 | |
166 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
166 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
167 | 167 | $this->endpoints = new $this->endpointMap; |
168 | 168 | |
169 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
169 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
170 | 170 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
171 | 171 | } |
172 | 172 | |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return mixed|null |
181 | 181 | */ |
182 | - public function __get(string $name){ |
|
182 | + public function __get(string $name) { |
|
183 | 183 | |
184 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
184 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
185 | 185 | return $this->{$name}; |
186 | 186 | } |
187 | 187 | |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function __call(string $name, array $arguments):ResponseInterface{ |
244 | 244 | |
245 | - if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){ |
|
245 | + if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) { |
|
246 | 246 | throw new ApiClientException('MagicAPI not available'); |
247 | 247 | } |
248 | 248 | |
249 | - if(!$this->endpoints->__isset($name)){ |
|
249 | + if (!$this->endpoints->__isset($name)) { |
|
250 | 250 | throw new ApiClientException('endpoint not found: "'.$name.'"'); |
251 | 251 | } |
252 | 252 | |
@@ -259,21 +259,21 @@ discard block |
||
259 | 259 | $path_elements = $m['path_elements'] ?? []; |
260 | 260 | $params_in_url = count($path_elements); |
261 | 261 | $params = $arguments[$params_in_url] ?? []; |
262 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
262 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
263 | 263 | |
264 | - if($params_in_url > 0){ |
|
264 | + if ($params_in_url > 0) { |
|
265 | 265 | |
266 | - if(count($urlparams) < $params_in_url){ |
|
266 | + if (count($urlparams) < $params_in_url) { |
|
267 | 267 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
268 | 268 | } |
269 | 269 | |
270 | 270 | $endpoint = sprintf($endpoint, ...$urlparams); |
271 | 271 | } |
272 | 272 | |
273 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
273 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
274 | 274 | $body = $arguments[$params_in_url + 1] ?? $params; |
275 | 275 | |
276 | - if($params === $body){ |
|
276 | + if ($params === $body) { |
|
277 | 277 | $params = []; |
278 | 278 | } |
279 | 279 | |
@@ -323,24 +323,24 @@ discard block |
||
323 | 323 | $request = $this->requestFactory |
324 | 324 | ->createRequest($method ?? 'GET', merge_query($this->apiURL.$path, $params ?? [])); |
325 | 325 | |
326 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
326 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
327 | 327 | $request = $request->withAddedHeader($header, $value); |
328 | 328 | } |
329 | 329 | |
330 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
330 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
331 | 331 | $contentType = strtolower($request->getHeaderLine('content-type')); |
332 | 332 | |
333 | 333 | // @todo: content type support |
334 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
334 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
335 | 335 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
336 | 336 | } |
337 | - elseif($contentType === 'application/json'){ |
|
337 | + elseif ($contentType === 'application/json') { |
|
338 | 338 | $body = $this->streamFactory->createStream(json_encode($body)); |
339 | 339 | } |
340 | 340 | |
341 | 341 | } |
342 | 342 | |
343 | - if($body instanceof StreamInterface){ |
|
343 | + if ($body instanceof StreamInterface) { |
|
344 | 344 | $request = $request |
345 | 345 | ->withBody($body) |
346 | 346 | ->withHeader('Content-length', $body->getSize()) |
@@ -356,15 +356,15 @@ discard block |
||
356 | 356 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
357 | 357 | |
358 | 358 | // get authorization only if we request the provider API |
359 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
359 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
360 | 360 | $token = $this->storage->getAccessToken($this->serviceName); |
361 | 361 | |
362 | 362 | // attempt to refresh an expired token |
363 | - if( |
|
363 | + if ( |
|
364 | 364 | $this instanceof TokenRefresh |
365 | 365 | && $this->options->tokenAutoRefresh |
366 | 366 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
367 | - ){ |
|
367 | + ) { |
|
368 | 368 | $token = $this->refreshAccessToken($token); |
369 | 369 | } |
370 | 370 |
@@ -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 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ->withHeader('Accept-Encoding', 'identity') |
64 | 64 | ; |
65 | 65 | |
66 | - foreach($this->authHeaders as $header => $value){ |
|
66 | + foreach ($this->authHeaders as $header => $value) { |
|
67 | 67 | $request = $request->withAddedHeader($header, $value); |
68 | 68 | } |
69 | 69 | |
@@ -80,20 +80,20 @@ discard block |
||
80 | 80 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
81 | 81 | parse_str(decompress_content($response), $data); |
82 | 82 | |
83 | - if(!$data || !is_array($data)){ |
|
83 | + if (!$data || !is_array($data)) { |
|
84 | 84 | throw new ProviderException('unable to parse token response'); |
85 | 85 | } |
86 | - elseif(isset($data['error'])){ |
|
86 | + elseif (isset($data['error'])) { |
|
87 | 87 | throw new ProviderException('error retrieving access token: '.$data['error']); |
88 | 88 | } |
89 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
89 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
90 | 90 | throw new ProviderException('invalid token'); |
91 | 91 | } |
92 | 92 | |
93 | - if( |
|
93 | + if ( |
|
94 | 94 | $checkCallbackConfirmed |
95 | 95 | && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') |
96 | - ){ |
|
96 | + ) { |
|
97 | 97 | throw new ProviderException('oauth callback unconfirmed'); |
98 | 98 | } |
99 | 99 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
141 | 141 | $parseURL = parse_url($url); |
142 | 142 | |
143 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
143 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
144 | 144 | throw new ProviderException('getSignature: invalid url'); |
145 | 145 | } |
146 | 146 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | |
149 | 149 | $signatureParams = array_merge($query, $params); |
150 | 150 | |
151 | - if(isset($signatureParams['oauth_signature'])){ |
|
151 | + if (isset($signatureParams['oauth_signature'])) { |
|
152 | 152 | unset($signatureParams['oauth_signature']); |
153 | 153 | } |
154 | 154 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $token->accessTokenSecret |
201 | 201 | ); |
202 | 202 | |
203 | - if(isset($query['oauth_session_handle'])){ |
|
203 | + if (isset($query['oauth_session_handle'])) { |
|
204 | 204 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
205 | 205 | } |
206 | 206 |
@@ -40,6 +40,6 @@ |
||
40 | 40 | * @property int $retries |
41 | 41 | * @property array $curl_multi_options |
42 | 42 | */ |
43 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
43 | +class OAuthOptions extends SettingsContainerAbstract { |
|
44 | 44 | use OAuthOptionsTrait, HTTPOptionsTrait; |
45 | 45 | } |