@@ -83,11 +83,9 @@ |
||
83 | 83 | |
84 | 84 | if(empty($data)){ |
85 | 85 | throw new ProviderException('unable to parse token response'); |
86 | - } |
|
87 | - elseif(isset($data['error'])){ |
|
86 | + } elseif(isset($data['error'])){ |
|
88 | 87 | throw new ProviderException('error retrieving access token: '.$data['error']); |
89 | - } |
|
90 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
88 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
91 | 89 | throw new ProviderException('invalid token'); |
92 | 90 | } |
93 | 91 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Implements an abstract OAuth1 provider with all methods required by the OAuth1Interface. |
30 | 30 | */ |
31 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
31 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * The request OAuth1 token URL |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | ->withHeader('Content-Length', '0') // tumblr requires a content-length header set |
68 | 68 | ; |
69 | 69 | |
70 | - foreach($this->authHeaders as $header => $value){ |
|
70 | + foreach ($this->authHeaders as $header => $value) { |
|
71 | 71 | $request = $request->withAddedHeader($header, $value); |
72 | 72 | } |
73 | 73 | |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
85 | 85 | $data = QueryUtil::parse(MessageUtil::decompress($response)); |
86 | 86 | |
87 | - if(empty($data)){ |
|
87 | + if (empty($data)) { |
|
88 | 88 | throw new ProviderException('unable to parse token response'); |
89 | 89 | } |
90 | - elseif(isset($data['error'])){ |
|
90 | + elseif (isset($data['error'])) { |
|
91 | 91 | throw new ProviderException('error retrieving access token: '.$data['error']); |
92 | 92 | } |
93 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
93 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
94 | 94 | throw new ProviderException('invalid token'); |
95 | 95 | } |
96 | 96 | |
97 | - if( |
|
97 | + if ( |
|
98 | 98 | $checkCallbackConfirmed |
99 | 99 | && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') |
100 | - ){ |
|
100 | + ) { |
|
101 | 101 | throw new ProviderException('oauth callback unconfirmed'); |
102 | 102 | } |
103 | 103 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
134 | 134 | $parsed = QueryUtil::parseUrl($url); |
135 | 135 | |
136 | - if(!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)){ |
|
136 | + if (!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)) { |
|
137 | 137 | throw new ProviderException('getSignature: invalid url'); |
138 | 138 | } |
139 | 139 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ]); |
151 | 151 | |
152 | 152 | // https://tools.ietf.org/html/rfc5849#section-3.4.2 |
153 | - $key = array_map('rawurlencode', [ |
|
153 | + $key = array_map('rawurlencode', [ |
|
154 | 154 | $this->options->secret, |
155 | 155 | $accessTokenSecret ?? '' |
156 | 156 | ]); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $token->accessTokenSecret |
198 | 198 | ); |
199 | 199 | |
200 | - if(isset($query['oauth_session_handle'])){ |
|
200 | + if (isset($query['oauth_session_handle'])) { |
|
201 | 201 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
202 | 202 | } |
203 | 203 |
@@ -16,6 +16,6 @@ |
||
16 | 16 | /** |
17 | 17 | * This class holds all settings related to the OAuth provider as well as the default HTTP client. |
18 | 18 | */ |
19 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
19 | +class OAuthOptions extends SettingsContainerAbstract { |
|
20 | 20 | use OAuthOptionsTrait, HTTPOptionsTrait; |
21 | 21 | } |
@@ -244,12 +244,10 @@ |
||
244 | 244 | if(is_array($body)){ |
245 | 245 | if($contentType === 'application/x-www-form-urlencoded'){ |
246 | 246 | $body = $this->streamFactory->createStream(QueryUtil::build($body, PHP_QUERY_RFC1738)); |
247 | - } |
|
248 | - elseif(in_array($contentType, ['application/json', 'application/vnd.api+json'])){ |
|
247 | + } elseif(in_array($contentType, ['application/json', 'application/vnd.api+json'])){ |
|
249 | 248 | $body = $this->streamFactory->createStream(json_encode($body)); |
250 | 249 | } |
251 | - } |
|
252 | - elseif(is_string($body)){ |
|
250 | + } elseif(is_string($body)){ |
|
253 | 251 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
254 | 252 | $body = $this->streamFactory->createStream($body); |
255 | 253 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @property string $serviceName |
44 | 44 | * @property string|null $userRevokeURL |
45 | 45 | */ |
46 | -abstract class OAuthProvider implements OAuthInterface{ |
|
46 | +abstract class OAuthProvider implements OAuthInterface { |
|
47 | 47 | use LoggerAwareTrait; |
48 | 48 | |
49 | 49 | protected const ALLOWED_PROPERTIES = [ |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | ClientInterface $http, |
138 | 138 | OAuthOptions|SettingsContainerInterface $options, |
139 | 139 | LoggerInterface $logger = null |
140 | - ){ |
|
140 | + ) { |
|
141 | 141 | $this->http = $http; |
142 | 142 | $this->storage = new MemoryStorage; |
143 | 143 | $this->options = $options; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function __get(string $name):mixed{ |
162 | 162 | |
163 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
163 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
164 | 164 | return $this->{$name}; |
165 | 165 | } |
166 | 166 | |
@@ -247,28 +247,28 @@ discard block |
||
247 | 247 | $request = $this->requestFactory |
248 | 248 | ->createRequest($method ?? 'GET', QueryUtil::merge($this->getRequestTarget($path), $params ?? [])); |
249 | 249 | |
250 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
250 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
251 | 251 | $request = $request->withAddedHeader($header, $value); |
252 | 252 | } |
253 | 253 | |
254 | - if($request->hasHeader('content-type')){ |
|
254 | + if ($request->hasHeader('content-type')) { |
|
255 | 255 | $contentType = strtolower($request->getHeaderLine('content-type')); |
256 | 256 | |
257 | - if(is_array($body)){ |
|
258 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
257 | + if (is_array($body)) { |
|
258 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
259 | 259 | $body = $this->streamFactory->createStream(QueryUtil::build($body, PHP_QUERY_RFC1738)); |
260 | 260 | } |
261 | - elseif(in_array($contentType, ['application/json', 'application/vnd.api+json'])){ |
|
261 | + elseif (in_array($contentType, ['application/json', 'application/vnd.api+json'])) { |
|
262 | 262 | $body = $this->streamFactory->createStream(json_encode($body)); |
263 | 263 | } |
264 | 264 | } |
265 | - elseif(is_string($body)){ |
|
265 | + elseif (is_string($body)) { |
|
266 | 266 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
267 | 267 | $body = $this->streamFactory->createStream($body); |
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | - if($body instanceof StreamInterface){ |
|
271 | + if ($body instanceof StreamInterface) { |
|
272 | 272 | $request = $request |
273 | 273 | ->withBody($body) |
274 | 274 | ->withHeader('Content-length', (string)$body->getSize()) |
@@ -290,18 +290,18 @@ discard block |
||
290 | 290 | protected function getRequestTarget(string $uri):string{ |
291 | 291 | $parsedURL = QueryUtil::parseUrl($uri); |
292 | 292 | |
293 | - if(!isset($parsedURL['path'])){ |
|
293 | + if (!isset($parsedURL['path'])) { |
|
294 | 294 | throw new ProviderException('invalid path'); |
295 | 295 | } |
296 | 296 | |
297 | 297 | // for some reason we were given a host name |
298 | - if(isset($parsedURL['host'])){ |
|
298 | + if (isset($parsedURL['host'])) { |
|
299 | 299 | $api = QueryUtil::parseUrl($this->apiURL); |
300 | 300 | $host = $api['host'] ?? null; |
301 | 301 | |
302 | 302 | // back out if it doesn't match |
303 | - if($parsedURL['host'] !== $host){ |
|
304 | - throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'] , $host)); |
|
303 | + if ($parsedURL['host'] !== $host) { |
|
304 | + throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'], $host)); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // we explicitly ignore any existing parameters here |
@@ -318,15 +318,15 @@ discard block |
||
318 | 318 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
319 | 319 | |
320 | 320 | // get authorization only if we request the provider API |
321 | - if(str_starts_with((string)$request->getUri(), $this->apiURL)){ |
|
321 | + if (str_starts_with((string)$request->getUri(), $this->apiURL)) { |
|
322 | 322 | $token = $this->storage->getAccessToken($this->serviceName); |
323 | 323 | |
324 | 324 | // attempt to refresh an expired token |
325 | - if( |
|
325 | + if ( |
|
326 | 326 | $this instanceof TokenRefresh |
327 | 327 | && $this->options->tokenAutoRefresh |
328 | 328 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
329 | - ){ |
|
329 | + ) { |
|
330 | 330 | $token = $this->refreshAccessToken($token); |
331 | 331 | } |
332 | 332 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * Implements an abstract OAuth storage adapter |
20 | 20 | */ |
21 | -abstract class OAuthStorageAbstract implements OAuthStorageInterface{ |
|
21 | +abstract class OAuthStorageAbstract implements OAuthStorageInterface { |
|
22 | 22 | use LoggerAwareTrait; |
23 | 23 | |
24 | 24 | protected OAuthOptions|SettingsContainerInterface $options; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * OAuthStorageAbstract constructor. |
29 | 29 | */ |
30 | - public function __construct(OAuthOptions|SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
30 | + public function __construct(OAuthOptions|SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
31 | 31 | $this->options = $options ?? new OAuthOptions; |
32 | 32 | $this->logger = $logger ?? new NullLogger; |
33 | 33 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public function setServiceName(string $service):OAuthStorageInterface{ |
39 | 39 | $service = trim($service); |
40 | 40 | |
41 | - if(empty($service)){ |
|
41 | + if (empty($service)) { |
|
42 | 42 | throw new OAuthStorageException('service name must not be empty'); |
43 | 43 | } |
44 | 44 | |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function getServiceName(string $service = null):string{ |
54 | 54 | |
55 | - if($service === null && !isset($this->serviceName)){ |
|
55 | + if ($service === null && !isset($this->serviceName)) { |
|
56 | 56 | throw new OAuthStorageException('invalid service'); |
57 | 57 | } |
58 | 58 | |
59 | 59 | $name = trim($service ?? $this->serviceName); |
60 | 60 | |
61 | - if(empty($name)){ |
|
61 | + if (empty($name)) { |
|
62 | 62 | throw new OAuthStorageException('service name must not be empty'); |
63 | 63 | } |
64 | 64 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function fromStorage(mixed $data):AccessToken{ |
80 | 80 | |
81 | - if(!is_string($data)){ |
|
81 | + if (!is_string($data)) { |
|
82 | 82 | throw new OAuthStorageException('invalid data'); |
83 | 83 | } |
84 | 84 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Implements a memory storage adapter. Memory storage is not persistent as tokens are only stored during script runtime. |
19 | 19 | */ |
20 | -class MemoryStorage extends OAuthStorageAbstract{ |
|
20 | +class MemoryStorage extends OAuthStorageAbstract { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * the token storage array |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getAccessToken(string $service = null):AccessToken{ |
45 | 45 | |
46 | - if($this->hasAccessToken($service)){ |
|
46 | + if ($this->hasAccessToken($service)) { |
|
47 | 47 | return $this->tokens[$this->getServiceName($service)]; |
48 | 48 | } |
49 | 49 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | public function clearAccessToken(string $service = null):OAuthStorageInterface{ |
66 | 66 | $serviceName = $this->getServiceName($service); |
67 | 67 | |
68 | - if(array_key_exists($serviceName, $this->tokens)){ |
|
68 | + if (array_key_exists($serviceName, $this->tokens)) { |
|
69 | 69 | unset($this->tokens[$serviceName]); |
70 | 70 | } |
71 | 71 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function clearAllAccessTokens():OAuthStorageInterface{ |
79 | 79 | |
80 | - foreach(array_keys($this->tokens) as $service){ |
|
80 | + foreach (array_keys($this->tokens) as $service) { |
|
81 | 81 | unset($this->tokens[$service]); |
82 | 82 | } |
83 | 83 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function getCSRFState(string $service = null):string{ |
102 | 102 | |
103 | - if($this->hasCSRFState($service)){ |
|
103 | + if ($this->hasCSRFState($service)) { |
|
104 | 104 | return $this->states[$this->getServiceName($service)]; |
105 | 105 | } |
106 | 106 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | public function clearCSRFState(string $service = null):OAuthStorageInterface{ |
123 | 123 | $serviceName = $this->getServiceName($service); |
124 | 124 | |
125 | - if(array_key_exists($serviceName, $this->states)){ |
|
125 | + if (array_key_exists($serviceName, $this->states)) { |
|
126 | 126 | unset($this->states[$serviceName]); |
127 | 127 | } |
128 | 128 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * Implements a session storage adapter. Session storage is half persistent as tokens are stored for the duration of the session. |
25 | 25 | */ |
26 | -class SessionStorage extends OAuthStorageAbstract{ |
|
26 | +class SessionStorage extends OAuthStorageAbstract { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * the key name for the token storage array in $_SESSION |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * SessionStorage constructor. |
40 | 40 | */ |
41 | - public function __construct(OAuthOptions|SettingsContainerInterface $options = null){ |
|
41 | + public function __construct(OAuthOptions|SettingsContainerInterface $options = null) { |
|
42 | 42 | parent::__construct($options); |
43 | 43 | |
44 | 44 | $this->tokenVar = $this->options->sessionTokenVar; |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | |
47 | 47 | // Determine if the session has started. |
48 | 48 | // @link http://stackoverflow.com/a/18542272/1470961 |
49 | - if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){ |
|
49 | + if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) { |
|
50 | 50 | session_start(); |
51 | 51 | } |
52 | 52 | |
53 | - if(!isset($_SESSION[$this->tokenVar])){ |
|
53 | + if (!isset($_SESSION[$this->tokenVar])) { |
|
54 | 54 | $_SESSION[$this->tokenVar] = []; |
55 | 55 | } |
56 | 56 | |
57 | - if(!isset($_SESSION[$this->stateVar])){ |
|
57 | + if (!isset($_SESSION[$this->stateVar])) { |
|
58 | 58 | $_SESSION[$this->stateVar] = []; |
59 | 59 | } |
60 | 60 | |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @codeCoverageIgnore |
67 | 67 | */ |
68 | - public function __destruct(){ |
|
69 | - if($this->options->sessionStart){ |
|
68 | + public function __destruct() { |
|
69 | + if ($this->options->sessionStart) { |
|
70 | 70 | session_write_close(); |
71 | 71 | } |
72 | 72 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function getAccessToken(string $service = null):AccessToken{ |
87 | 87 | |
88 | - if($this->hasAccessToken($service)){ |
|
88 | + if ($this->hasAccessToken($service)) { |
|
89 | 89 | return $this->fromStorage($_SESSION[$this->tokenVar][$this->getServiceName($service)]); |
90 | 90 | } |
91 | 91 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | public function clearAccessToken(string $service = null):OAuthStorageInterface{ |
106 | 106 | $serviceName = $this->getServiceName($service); |
107 | 107 | |
108 | - if(array_key_exists($serviceName, $_SESSION[$this->tokenVar])){ |
|
108 | + if (array_key_exists($serviceName, $_SESSION[$this->tokenVar])) { |
|
109 | 109 | unset($_SESSION[$this->tokenVar][$serviceName]); |
110 | 110 | } |
111 | 111 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function clearAllAccessTokens():OAuthStorageInterface{ |
119 | 119 | |
120 | - foreach(array_keys($_SESSION[$this->tokenVar]) as $service){ |
|
120 | + foreach (array_keys($_SESSION[$this->tokenVar]) as $service) { |
|
121 | 121 | unset($_SESSION[$this->tokenVar][$service]); |
122 | 122 | } |
123 | 123 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function getCSRFState(string $service = null):string{ |
142 | 142 | |
143 | - if($this->hasCSRFState($service)){ |
|
143 | + if ($this->hasCSRFState($service)) { |
|
144 | 144 | return $_SESSION[$this->stateVar][$this->getServiceName($service)]; |
145 | 145 | } |
146 | 146 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | public function clearCSRFState(string $service = null):OAuthStorageInterface{ |
161 | 161 | $serviceName = $this->getServiceName($service); |
162 | 162 | |
163 | - if(array_key_exists($serviceName, $_SESSION[$this->stateVar])){ |
|
163 | + if (array_key_exists($serviceName, $_SESSION[$this->stateVar])) { |
|
164 | 164 | unset($_SESSION[$this->stateVar][$serviceName]); |
165 | 165 | } |
166 | 166 |
@@ -16,7 +16,7 @@ |
||
16 | 16 | /** |
17 | 17 | * Specifies the methods required for an OAuth storage adapter |
18 | 18 | */ |
19 | -interface OAuthStorageInterface extends LoggerAwareInterface{ |
|
19 | +interface OAuthStorageInterface extends LoggerAwareInterface { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Sets the current service provider name |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * Implements an abstract OAuth2 provider with all methods required by the OAuth2Interface. |
35 | 35 | * It also implements the ClientCredentials, CSRFToken and TokenRefresh interfaces in favor over traits. |
36 | 36 | */ |
37 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
37 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Specifies the authentication method: |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | 'type' => 'web_server', |
92 | 92 | ]); |
93 | 93 | |
94 | - if(!empty($scopes)){ |
|
94 | + if (!empty($scopes)) { |
|
95 | 95 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
96 | 96 | } |
97 | 97 | |
98 | - if($this instanceof CSRFToken){ |
|
98 | + if ($this instanceof CSRFToken) { |
|
99 | 99 | $params = $this->setState($params); |
100 | 100 | } |
101 | 101 | |
@@ -114,19 +114,19 @@ discard block |
||
114 | 114 | // silly amazon sends compressed data... |
115 | 115 | $data = json_decode(MessageUtil::decompress($response), true, 512, JSON_THROW_ON_ERROR); |
116 | 116 | |
117 | - if(!is_array($data)){ |
|
117 | + if (!is_array($data)) { |
|
118 | 118 | throw new ProviderException('unable to parse token response'); |
119 | 119 | } |
120 | 120 | |
121 | - foreach(['error_description', 'error'] as $field){ |
|
121 | + foreach (['error_description', 'error'] as $field) { |
|
122 | 122 | |
123 | - if(isset($data[$field])){ |
|
123 | + if (isset($data[$field])) { |
|
124 | 124 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
125 | 125 | } |
126 | 126 | |
127 | 127 | } |
128 | 128 | |
129 | - if(!isset($data['access_token'])){ |
|
129 | + if (!isset($data['access_token'])) { |
|
130 | 130 | throw new ProviderException('token missing'); |
131 | 131 | } |
132 | 132 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public function getAccessToken(string $code, string $state = null):AccessToken{ |
150 | 150 | |
151 | - if($this instanceof CSRFToken){ |
|
151 | + if ($this instanceof CSRFToken) { |
|
152 | 152 | $this->checkState($state); |
153 | 153 | } |
154 | 154 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | ->withHeader('Accept-Encoding', 'identity') |
167 | 167 | ->withBody($this->streamFactory->createStream(QueryUtil::build($body, PHP_QUERY_RFC1738))); |
168 | 168 | |
169 | - foreach($this->authHeaders as $header => $value){ |
|
169 | + foreach ($this->authHeaders as $header => $value) { |
|
170 | 170 | $request = $request->withHeader($header, $value); |
171 | 171 | } |
172 | 172 | |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{ |
184 | 184 | |
185 | - if($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER){ |
|
185 | + if ($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER) { |
|
186 | 186 | return $request->withHeader('Authorization', $this->authMethodHeader.' '.$token->accessToken); |
187 | 187 | } |
188 | 188 | |
189 | - if($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY){ |
|
189 | + if ($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY) { |
|
190 | 190 | $uri = QueryUtil::merge((string)$request->getUri(), [$this->authMethodQuery => $token->accessToken]); |
191 | 191 | |
192 | 192 | return $request->withUri($this->uriFactory->createUri($uri)); |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function getClientCredentialsToken(array $scopes = null):AccessToken{ |
206 | 206 | |
207 | - if(!$this instanceof ClientCredentials){ |
|
207 | + if (!$this instanceof ClientCredentials) { |
|
208 | 208 | throw new ProviderException('client credentials token not supported'); |
209 | 209 | } |
210 | 210 | |
211 | 211 | $params = ['grant_type' => 'client_credentials']; |
212 | 212 | |
213 | - if(!empty($scopes)){ |
|
213 | + if (!empty($scopes)) { |
|
214 | 214 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
215 | 215 | } |
216 | 216 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | ->withBody($this->streamFactory->createStream(QueryUtil::build($params, PHP_QUERY_RFC1738))) |
223 | 223 | ; |
224 | 224 | |
225 | - foreach($this->authHeaders as $header => $value){ |
|
225 | + foreach ($this->authHeaders as $header => $value) { |
|
226 | 226 | $request = $request->withAddedHeader($header, $value); |
227 | 227 | } |
228 | 228 | |
@@ -243,17 +243,17 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function refreshAccessToken(AccessToken $token = null):AccessToken{ |
245 | 245 | |
246 | - if(!$this instanceof TokenRefresh){ |
|
246 | + if (!$this instanceof TokenRefresh) { |
|
247 | 247 | throw new ProviderException('token refresh not supported'); |
248 | 248 | } |
249 | 249 | |
250 | - if($token === null){ |
|
250 | + if ($token === null) { |
|
251 | 251 | $token = $this->storage->getAccessToken($this->serviceName); |
252 | 252 | } |
253 | 253 | |
254 | 254 | $refreshToken = $token->refreshToken; |
255 | 255 | |
256 | - if(empty($refreshToken)){ |
|
256 | + if (empty($refreshToken)) { |
|
257 | 257 | throw new ProviderException( |
258 | 258 | sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires)) |
259 | 259 | ); |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | ->withBody($this->streamFactory->createStream(QueryUtil::build($body, PHP_QUERY_RFC1738))) |
275 | 275 | ; |
276 | 276 | |
277 | - foreach($this->authHeaders as $header => $value){ |
|
277 | + foreach ($this->authHeaders as $header => $value) { |
|
278 | 278 | $request = $request->withAddedHeader($header, $value); |
279 | 279 | } |
280 | 280 | |
281 | 281 | $newToken = $this->parseTokenResponse($this->http->sendRequest($request)); |
282 | 282 | |
283 | - if(empty($newToken->refreshToken)){ |
|
283 | + if (empty($newToken->refreshToken)) { |
|
284 | 284 | $newToken->refreshToken = $refreshToken; |
285 | 285 | } |
286 | 286 | |
@@ -300,17 +300,17 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function checkState(string $state = null):void{ |
302 | 302 | |
303 | - if(!$this instanceof CSRFToken){ |
|
303 | + if (!$this instanceof CSRFToken) { |
|
304 | 304 | throw new ProviderException('CSRF protection not supported'); |
305 | 305 | } |
306 | 306 | |
307 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
307 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
308 | 308 | throw new ProviderException('invalid state for '.$this->serviceName); |
309 | 309 | } |
310 | 310 | |
311 | 311 | $knownState = $this->storage->getCSRFState($this->serviceName); |
312 | 312 | |
313 | - if(!hash_equals($knownState, $state)){ |
|
313 | + if (!hash_equals($knownState, $state)) { |
|
314 | 314 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
315 | 315 | } |
316 | 316 | |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public function setState(array $params):array{ |
329 | 329 | |
330 | - if(!$this instanceof CSRFToken){ |
|
330 | + if (!$this instanceof CSRFToken) { |
|
331 | 331 | throw new ProviderException('CSRF protection not supported'); |
332 | 332 | } |
333 | 333 | |
334 | - if(!isset($params['state'])){ |
|
334 | + if (!isset($params['state'])) { |
|
335 | 335 | $params['state'] = sha1(random_bytes(256)); |
336 | 336 | } |
337 | 337 |