@@ -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 |
@@ -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,17 +220,17 @@ 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 | throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))); |
235 | 235 | } |
236 | 236 | |
@@ -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 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth; |
14 | 14 | |
15 | -trait OAuthOptionsTrait{ |
|
15 | +trait OAuthOptionsTrait { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * The application key (or id) given by your provider |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth\Core; |
14 | 14 | |
15 | -interface TokenRefresh{ |
|
15 | +interface TokenRefresh { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Tries to refresh an existing access token with an associated refresh token |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth\Core; |
14 | 14 | |
15 | -interface OAuth1Interface extends OAuthInterface{ |
|
15 | +interface OAuth1Interface extends OAuthInterface { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Obtains an OAuth1 request token and returns an AccessToken |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth\Core; |
14 | 14 | |
15 | -interface ClientCredentials{ |
|
15 | +interface ClientCredentials { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Obtains an OAuth2 client credentials token and returns an AccessToken |
@@ -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 | * Stores an AccessToken for the given $service |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | use function is_string; |
20 | 20 | |
21 | -abstract class OAuthStorageAbstract implements OAuthStorageInterface{ |
|
21 | +abstract class OAuthStorageAbstract implements OAuthStorageInterface { |
|
22 | 22 | use LoggerAwareTrait; |
23 | 23 | |
24 | 24 | /** |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
33 | 33 | * @param \Psr\Log\LoggerInterface|null $logger |
34 | 34 | */ |
35 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
35 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
36 | 36 | $this->options = $options ?? new OAuthOptions; |
37 | 37 | |
38 | 38 | $this->setLogger($logger ?? new NullLogger); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function fromStorage($data):AccessToken{ |
56 | 56 | |
57 | - if(!is_string($data)){ |
|
57 | + if (!is_string($data)) { |
|
58 | 58 | throw new OAuthStorageException('invalid data'); |
59 | 59 | } |
60 | 60 |
@@ -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 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getAccessToken(string $service):AccessToken{ |
44 | 44 | |
45 | - if($this->hasAccessToken($service)){ |
|
45 | + if ($this->hasAccessToken($service)) { |
|
46 | 46 | return $this->tokens[$service]; |
47 | 47 | } |
48 | 48 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function clearAccessToken(string $service):bool{ |
63 | 63 | |
64 | - if(array_key_exists($service, $this->tokens)){ |
|
64 | + if (array_key_exists($service, $this->tokens)) { |
|
65 | 65 | unset($this->tokens[$service]); |
66 | 66 | } |
67 | 67 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function clearAllAccessTokens():bool{ |
75 | 75 | |
76 | - foreach(array_keys($this->tokens) as $service){ |
|
76 | + foreach (array_keys($this->tokens) as $service) { |
|
77 | 77 | unset($this->tokens[$service]); |
78 | 78 | } |
79 | 79 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function getCSRFState(string $service):string{ |
98 | 98 | |
99 | - if($this->hasCSRFState($service)){ |
|
99 | + if ($this->hasCSRFState($service)) { |
|
100 | 100 | return $this->states[$service]; |
101 | 101 | } |
102 | 102 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function clearCSRFState(string $service):bool{ |
117 | 117 | |
118 | - if(array_key_exists($service, $this->states)){ |
|
118 | + if (array_key_exists($service, $this->states)) { |
|
119 | 119 | unset($this->states[$service]); |
120 | 120 | } |
121 | 121 |
@@ -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 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function getAccessToken(string $service):AccessToken{ |
85 | 85 | |
86 | - if($this->hasAccessToken($service)){ |
|
86 | + if ($this->hasAccessToken($service)) { |
|
87 | 87 | return $this->fromStorage($_SESSION[$this->sessionVar][$service]); |
88 | 88 | } |
89 | 89 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function clearAccessToken(string $service):bool{ |
104 | 104 | |
105 | - if(array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
105 | + if (array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
106 | 106 | unset($_SESSION[$this->sessionVar][$service]); |
107 | 107 | } |
108 | 108 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function clearAllAccessTokens():bool{ |
116 | 116 | |
117 | - foreach(array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
117 | + foreach (array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
118 | 118 | unset($_SESSION[$this->sessionVar][$service]); |
119 | 119 | } |
120 | 120 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function getCSRFState(string $service):string{ |
139 | 139 | |
140 | - if($this->hasCSRFState($service)){ |
|
140 | + if ($this->hasCSRFState($service)) { |
|
141 | 141 | return $_SESSION[$this->stateVar][$service]; |
142 | 142 | } |
143 | 143 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function clearCSRFState(string $service):bool{ |
158 | 158 | |
159 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
159 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
160 | 160 | unset($_SESSION[$this->stateVar][$service]); |
161 | 161 | } |
162 | 162 |