@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @property string $ca_info |
56 | 56 | * @property int $max_redirects |
57 | 57 | */ |
58 | -class OAuthOptions implements ContainerInterface{ |
|
58 | +class OAuthOptions implements ContainerInterface { |
|
59 | 59 | use OAuthOptionsTrait, HTTPOptionsTrait, MemzeroDestructorTrait, Container{ |
60 | 60 | __construct as protected containerConstruct; |
61 | 61 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param array|null $properties |
67 | 67 | */ |
68 | - public function __construct(array $properties = null){ |
|
68 | + public function __construct(array $properties = null) { |
|
69 | 69 | // enable encryption by default if possible... |
70 | 70 | $this->useEncryption = extension_loaded('sodium'); |
71 | 71 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @method array setState(array $params) |
26 | 26 | * @method \chillerlan\OAuth\Providers\OAuth2Interface checkState(string $state = null) |
27 | 27 | */ |
28 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
28 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @var int |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param \chillerlan\Traits\ContainerInterface $options |
61 | 61 | * @param array $scopes |
62 | 62 | */ |
63 | - public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, array $scopes = null){ |
|
63 | + public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, array $scopes = null) { |
|
64 | 64 | parent::__construct($http, $storage, $options); |
65 | 65 | |
66 | 66 | $this->scopes = $scopes ?? []; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function getAuthURL(array $params = null):string{ |
75 | 75 | $params = $this->getAuthURLParams($params ?? []); |
76 | 76 | |
77 | - if($this instanceof CSRFToken){ |
|
77 | + if ($this instanceof CSRFToken) { |
|
78 | 78 | $params = $this->setState($params); |
79 | 79 | } |
80 | 80 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | protected function getAuthURLParams(array $params):array { |
90 | 90 | |
91 | 91 | // this should not be here |
92 | - if(isset($params['client_secret'])){ |
|
92 | + if (isset($params['client_secret'])) { |
|
93 | 93 | unset($params['client_secret']); |
94 | 94 | } |
95 | 95 | |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | protected function parseTokenResponse(HTTPResponseInterface $response):Token{ |
112 | 112 | $data = $response->json_array; |
113 | 113 | |
114 | - if(!is_array($data)){ |
|
114 | + if (!is_array($data)) { |
|
115 | 115 | throw new ProviderException('unable to parse token response'); |
116 | 116 | } |
117 | 117 | |
118 | - foreach(['error_description', 'error'] as $field){ |
|
118 | + foreach (['error_description', 'error'] as $field) { |
|
119 | 119 | |
120 | - if(isset($data[$field])){ |
|
120 | + if (isset($data[$field])) { |
|
121 | 121 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
122 | 122 | } |
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - if(!isset($data['access_token'])){ |
|
126 | + if (!isset($data['access_token'])) { |
|
127 | 127 | throw new ProviderException('token missing'); |
128 | 128 | } |
129 | 129 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getAccessToken(string $code, string $state = null):Token{ |
151 | 151 | |
152 | - if($this instanceof CSRFToken){ |
|
152 | + if ($this instanceof CSRFToken) { |
|
153 | 153 | $this->checkState($state); |
154 | 154 | } |
155 | 155 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $token = $this->storage->retrieveAccessToken($this->serviceName); |
204 | 204 | |
205 | 205 | // attempt to refresh an expired token |
206 | - if($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
206 | + if ($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
207 | 207 | $token = $this->refreshAccessToken($token); |
208 | 208 | } |
209 | 209 | |
@@ -212,15 +212,15 @@ discard block |
||
212 | 212 | $params = array_merge($query, $params ?? []); |
213 | 213 | $headers = $headers ?? []; |
214 | 214 | |
215 | - if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){ |
|
215 | + if (array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)) { |
|
216 | 216 | $headers = array_merge($headers, [ |
217 | 217 | 'Authorization' => $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken, |
218 | 218 | ]); |
219 | 219 | } |
220 | - elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){ |
|
220 | + elseif (array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)) { |
|
221 | 221 | $params[$this::AUTH_METHODS_QUERY[$this->authMethod]] = $token->accessToken; |
222 | 222 | } |
223 | - else{ |
|
223 | + else { |
|
224 | 224 | throw new ProviderException('invalid auth type'); |
225 | 225 | } |
226 | 226 |
@@ -216,11 +216,9 @@ |
||
216 | 216 | $headers = array_merge($headers, [ |
217 | 217 | 'Authorization' => $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken, |
218 | 218 | ]); |
219 | - } |
|
220 | - elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){ |
|
219 | + } elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){ |
|
221 | 220 | $params[$this::AUTH_METHODS_QUERY[$this->authMethod]] = $token->accessToken; |
222 | - } |
|
223 | - else{ |
|
221 | + } else{ |
|
224 | 222 | throw new ProviderException('invalid auth type'); |
225 | 223 | } |
226 | 224 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @property \chillerlan\OAuth\Storage\TokenStorageInterface $storage |
22 | 22 | * @property \chillerlan\OAuth\OAuthOptions $options |
23 | 23 | */ |
24 | -trait OAuth2TokenRefreshTrait{ |
|
24 | +trait OAuth2TokenRefreshTrait { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param \chillerlan\OAuth\Token $token |
@@ -31,15 +31,15 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function refreshAccessToken(Token $token = null):Token{ |
33 | 33 | |
34 | - if($token === null){ |
|
34 | + if ($token === null) { |
|
35 | 35 | $token = $this->storage->retrieveAccessToken($this->serviceName); |
36 | 36 | } |
37 | 37 | |
38 | 38 | $refreshToken = $token->refreshToken; |
39 | 39 | |
40 | - if(empty($refreshToken)){ |
|
40 | + if (empty($refreshToken)) { |
|
41 | 41 | |
42 | - if(!$this instanceof AccessTokenForRefresh){ |
|
42 | + if (!$this instanceof AccessTokenForRefresh) { |
|
43 | 43 | throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))); |
44 | 44 | } |
45 | 45 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | ) |
56 | 56 | ); |
57 | 57 | |
58 | - if(!$newToken->refreshToken){ |
|
58 | + if (!$newToken->refreshToken) { |
|
59 | 59 | $newToken->refreshToken = $refreshToken; |
60 | 60 | } |
61 | 61 |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param \chillerlan\OAuth\Storage\TokenStorageInterface $storage |
95 | 95 | * @param \chillerlan\Traits\ContainerInterface $options |
96 | 96 | */ |
97 | - public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options){ |
|
97 | + public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options) { |
|
98 | 98 | $this->setHTTPClient($http); |
99 | 99 | |
100 | 100 | $this->storage = $storage; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | // @todo |
106 | 106 | $file = __DIR__.'/../API/'.$this->serviceName.'.json'; |
107 | 107 | |
108 | - if(is_file($file)){ |
|
108 | + if (is_file($file)) { |
|
109 | 109 | $this->apiMethods = json_decode(file_get_contents($file)); |
110 | 110 | } |
111 | 111 | |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | * @return \chillerlan\HTTP\HTTPResponseInterface|null |
143 | 143 | * @throws \chillerlan\OAuth\API\OAuthAPIClientException |
144 | 144 | */ |
145 | - public function __call(string $name, array $arguments){ |
|
146 | - if(array_key_exists($name, $this->apiMethods)){ |
|
145 | + public function __call(string $name, array $arguments) { |
|
146 | + if (array_key_exists($name, $this->apiMethods)) { |
|
147 | 147 | |
148 | 148 | $m = $this->apiMethods->{$name}; |
149 | 149 | |
@@ -154,25 +154,25 @@ discard block |
||
154 | 154 | $path_elements = $m->path_elements ?? []; |
155 | 155 | $params_in_url = count($path_elements); |
156 | 156 | $params = $arguments[$params_in_url] ?? null; |
157 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
157 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
158 | 158 | |
159 | - if($params_in_url > 0){ |
|
159 | + if ($params_in_url > 0) { |
|
160 | 160 | |
161 | - if(count($urlparams) < $params_in_url){ |
|
161 | + if (count($urlparams) < $params_in_url) { |
|
162 | 162 | throw new OAuthAPIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
163 | 163 | } |
164 | 164 | |
165 | 165 | $endpoint = sprintf($endpoint, ...$urlparams); |
166 | 166 | } |
167 | 167 | |
168 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
168 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
169 | 169 | $body = $arguments[$params_in_url + 1] ?? $params; |
170 | 170 | |
171 | - if($params === $body){ |
|
171 | + if ($params === $body) { |
|
172 | 172 | $params = null; |
173 | 173 | } |
174 | 174 | |
175 | - if(is_array($body) && isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'json') !== false){ |
|
175 | + if (is_array($body) && isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'json') !== false) { |
|
176 | 176 | $body = json_encode($body); |
177 | 177 | } |
178 | 178 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $body = $this->checkQueryParams($body); |
183 | 183 | |
184 | 184 | // twitter is v picky |
185 | - if($this instanceof Twitter){ |
|
185 | + if ($this instanceof Twitter) { |
|
186 | 186 | $params = $this->checkQueryParams($params, true); |
187 | 187 | $body = $this->checkQueryParams($body, true); |
188 | 188 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth\Providers; |
14 | 14 | |
15 | -interface AccessTokenForRefresh{ |
|
15 | +interface AccessTokenForRefresh { |
|
16 | 16 | |
17 | 17 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | * @property string $accessTokenURL |
22 | 22 | * @property \chillerlan\OAuth\Storage\TokenStorageInterface $storage |
23 | 23 | */ |
24 | -trait OAuth2ClientCredentialsTrait{ |
|
24 | +trait OAuth2ClientCredentialsTrait { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param array $scopes |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth\Providers; |
14 | 14 | |
15 | -interface CSRFToken{ |
|
15 | +interface CSRFToken { |
|
16 | 16 | |
17 | 17 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @property string $serviceName |
19 | 19 | * @property \chillerlan\OAuth\Storage\TokenStorageInterface $storage |
20 | 20 | */ |
21 | -trait CSRFTokenTrait{ |
|
21 | +trait CSRFTokenTrait { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @param string|null $state |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected function checkState(string $state = null):OAuth2Interface{ |
30 | 30 | |
31 | - if(empty($state) || !$this->storage->hasAuthorizationState($this->serviceName)){ |
|
31 | + if (empty($state) || !$this->storage->hasAuthorizationState($this->serviceName)) { |
|
32 | 32 | throw new ProviderException('invalid state for '.$this->serviceName); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $knownState = $this->storage->retrieveAuthorizationState($this->serviceName); |
36 | 36 | |
37 | - if(!hash_equals($knownState, $state)){ |
|
37 | + if (!hash_equals($knownState, $state)) { |
|
38 | 38 | throw new ProviderException('invalid authorization state: '.$this->serviceName.' '.$state); |
39 | 39 | } |
40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected function setState(array $params):array { |
50 | 50 | |
51 | - if(!isset($params['state'])){ |
|
51 | + if (!isset($params['state'])) { |
|
52 | 52 | $params['state'] = sha1(random_bytes(256)); |
53 | 53 | } |
54 | 54 |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\OAuthException; |
16 | 16 | |
17 | -class ProviderException extends OAuthException{} |
|
17 | +class ProviderException extends OAuthException {} |