@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\Token; |
16 | 16 | |
17 | -class MemoryTokenStorage extends TokenStorageAbstract{ |
|
17 | +class MemoryTokenStorage extends TokenStorageAbstract { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var array |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getAccessToken(string $service):Token{ |
48 | 48 | |
49 | - if($this->hasAccessToken($service)){ |
|
49 | + if ($this->hasAccessToken($service)) { |
|
50 | 50 | return $this->tokens[$service]; |
51 | 51 | } |
52 | 52 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function clearAccessToken(string $service):TokenStorageInterface{ |
71 | 71 | |
72 | - if(array_key_exists($service, $this->tokens)){ |
|
72 | + if (array_key_exists($service, $this->tokens)) { |
|
73 | 73 | unset($this->tokens[$service]); |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function clearAllAccessTokens():TokenStorageInterface{ |
83 | 83 | |
84 | - foreach(array_keys($this->tokens) as $service){ |
|
84 | + foreach (array_keys($this->tokens) as $service) { |
|
85 | 85 | unset($this->tokens[$service]); // trigger the memzero destructor |
86 | 86 | } |
87 | 87 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getCSRFState(string $service):string{ |
112 | 112 | |
113 | - if($this->hasCSRFState($service)){ |
|
113 | + if ($this->hasCSRFState($service)) { |
|
114 | 114 | return $this->states[$service]; |
115 | 115 | } |
116 | 116 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function clearCSRFState(string $service):TokenStorageInterface{ |
135 | 135 | |
136 | - if(array_key_exists($service, $this->states)){ |
|
136 | + if (array_key_exists($service, $this->states)) { |
|
137 | 137 | unset($this->states[$service]); |
138 | 138 | } |
139 | 139 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * - the session is running through a session handler that already encrypts the session data. nothing to do here. |
22 | 22 | * - the session runs in memory - i think it's silly to encrypt there. sodium_memzero() galore! |
23 | 23 | */ |
24 | -class SessionTokenStorage extends TokenStorageAbstract{ |
|
24 | +class SessionTokenStorage extends TokenStorageAbstract { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @var bool |
@@ -43,21 +43,21 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param \chillerlan\Traits\ContainerInterface|null $options |
45 | 45 | */ |
46 | - public function __construct(ContainerInterface $options = null){ |
|
46 | + public function __construct(ContainerInterface $options = null) { |
|
47 | 47 | parent::__construct($options); |
48 | 48 | |
49 | 49 | $this->sessionVar = $this->options->sessionTokenVar; |
50 | 50 | $this->stateVar = $this->options->sessionStateVar; |
51 | 51 | |
52 | - if($this->options->sessionStart && !$this->sessionIsActive()){ |
|
52 | + if ($this->options->sessionStart && !$this->sessionIsActive()) { |
|
53 | 53 | session_start(); |
54 | 54 | } |
55 | 55 | |
56 | - if(!isset($_SESSION[$this->sessionVar])){ |
|
56 | + if (!isset($_SESSION[$this->sessionVar])) { |
|
57 | 57 | $_SESSION[$this->sessionVar] = []; |
58 | 58 | } |
59 | 59 | |
60 | - if(!isset($_SESSION[$this->stateVar])){ |
|
60 | + if (!isset($_SESSION[$this->stateVar])) { |
|
61 | 61 | $_SESSION[$this->stateVar] = []; |
62 | 62 | } |
63 | 63 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * Destructor. |
68 | 68 | */ |
69 | - public function __destruct(){ |
|
70 | - if($this->options->sessionStart){ |
|
69 | + public function __destruct() { |
|
70 | + if ($this->options->sessionStart) { |
|
71 | 71 | session_write_close(); |
72 | 72 | } |
73 | 73 | } |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | public function storeAccessToken(string $service, Token $token):TokenStorageInterface{ |
82 | 82 | $token = $token->__toJSON(); |
83 | 83 | |
84 | - if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
|
84 | + if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) { |
|
85 | 85 | $_SESSION[$this->sessionVar][$service] = $token; |
86 | 86 | } |
87 | - else{ |
|
87 | + else { |
|
88 | 88 | $_SESSION[$this->sessionVar] = [$service => $token]; |
89 | 89 | } |
90 | 90 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function getAccessToken(string $service):Token{ |
101 | 101 | |
102 | - if($this->hasAccessToken($service)){ |
|
102 | + if ($this->hasAccessToken($service)) { |
|
103 | 103 | return (new Token)->__fromJSON($_SESSION[$this->sessionVar][$service]); |
104 | 104 | } |
105 | 105 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function clearAccessToken(string $service):TokenStorageInterface{ |
124 | 124 | |
125 | - if(array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
125 | + if (array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
126 | 126 | unset($_SESSION[$this->sessionVar][$service]); |
127 | 127 | } |
128 | 128 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function clearAllAccessTokens():TokenStorageInterface{ |
136 | 136 | |
137 | - foreach(array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
137 | + foreach (array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
138 | 138 | unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor |
139 | 139 | } |
140 | 140 | |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function storeCSRFState(string $service, string $state):TokenStorageInterface{ |
153 | 153 | |
154 | - if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
|
154 | + if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) { |
|
155 | 155 | $_SESSION[$this->stateVar][$service] = $state; |
156 | 156 | } |
157 | - else{ |
|
157 | + else { |
|
158 | 158 | $_SESSION[$this->stateVar] = [$service => $state]; |
159 | 159 | } |
160 | 160 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function getCSRFState(string $service):string{ |
171 | 171 | |
172 | - if($this->hasCSRFState($service)){ |
|
172 | + if ($this->hasCSRFState($service)) { |
|
173 | 173 | return $_SESSION[$this->stateVar][$service]; |
174 | 174 | } |
175 | 175 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function clearCSRFState(string $service):TokenStorageInterface{ |
194 | 194 | |
195 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
195 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
196 | 196 | unset($_SESSION[$this->stateVar][$service]); |
197 | 197 | } |
198 | 198 |
@@ -88,14 +88,14 @@ |
||
88 | 88 | * @param \chillerlan\OAuth\Storage\TokenStorageInterface $storage |
89 | 89 | * @param \chillerlan\Traits\ContainerInterface $options |
90 | 90 | */ |
91 | - public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options){ |
|
91 | + public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options) { |
|
92 | 92 | $this->setHTTPClient($http); |
93 | 93 | |
94 | 94 | $this->storage = $storage; |
95 | 95 | $this->options = $options; |
96 | 96 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
97 | 97 | |
98 | - if($this instanceof ApiClientInterface){ |
|
98 | + if ($this instanceof ApiClientInterface) { |
|
99 | 99 | $this->loadEndpoints(); |
100 | 100 | } |
101 | 101 |
@@ -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->getAccessToken($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 |
@@ -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->getAccessToken($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 |
@@ -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->hasCSRFState($this->serviceName)){ |
|
31 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
32 | 32 | throw new ProviderException('invalid state for '.$this->serviceName); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $knownState = $this->storage->getCSRFState($this->serviceName); |
36 | 36 | |
37 | - if(!hash_equals($knownState, $state)){ |
|
37 | + if (!hash_equals($knownState, $state)) { |
|
38 | 38 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
39 | 39 | } |
40 | 40 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | protected function setState(array $params):array { |
51 | 51 | |
52 | - if(!isset($params['state'])){ |
|
52 | + if (!isset($params['state'])) { |
|
53 | 53 | $params['state'] = sha1(random_bytes(256)); |
54 | 54 | } |
55 | 55 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use chillerlan\HTTP\HTTPResponseInterface; |
17 | 17 | use DateTime; |
18 | 18 | |
19 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
19 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var string |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return \chillerlan\OAuth\Token |
48 | 48 | */ |
49 | 49 | public function getRequestToken():Token { |
50 | - $params = $this->getRequestTokenHeaderParams(); |
|
50 | + $params = $this->getRequestTokenHeaderParams(); |
|
51 | 51 | |
52 | 52 | return $this->parseTokenResponse( |
53 | 53 | $this->httpPOST( |
@@ -72,19 +72,19 @@ discard block |
||
72 | 72 | protected function parseTokenResponse(HTTPResponseInterface $response, bool $checkCallbackConfirmed = null):Token { |
73 | 73 | parse_str($response->body, $data); |
74 | 74 | |
75 | - if(!$data || !is_array($data)){ |
|
75 | + if (!$data || !is_array($data)) { |
|
76 | 76 | throw new ProviderException('unable to parse token response'); |
77 | 77 | } |
78 | - elseif(isset($data['error'])){ |
|
78 | + elseif (isset($data['error'])) { |
|
79 | 79 | throw new ProviderException('error retrieving access token: '.$data['error']); |
80 | 80 | } |
81 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
81 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
82 | 82 | throw new ProviderException('token missing'); |
83 | 83 | } |
84 | 84 | |
85 | - if(($checkCallbackConfirmed ?? false) |
|
85 | + if (($checkCallbackConfirmed ?? false) |
|
86 | 86 | && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') |
87 | - ){ |
|
87 | + ) { |
|
88 | 88 | throw new ProviderException('oauth callback unconfirmed'); |
89 | 89 | } |
90 | 90 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | public function getSignature(string $url, array $params, string $method = null):string { |
148 | 148 | $parseURL = parse_url($url); |
149 | 149 | |
150 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
150 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
151 | 151 | throw new ProviderException('getSignature: invalid url'); |
152 | 152 | } |
153 | 153 | |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return string |
173 | 173 | */ |
174 | - protected function getSignatureData(string $signatureURL, array $signatureParams, string $method){ |
|
174 | + protected function getSignatureData(string $signatureURL, array $signatureParams, string $method) { |
|
175 | 175 | |
176 | - if(isset($signatureParams['oauth_signature'])){ |
|
176 | + if (isset($signatureParams['oauth_signature'])) { |
|
177 | 177 | unset($signatureParams['oauth_signature']); |
178 | 178 | } |
179 | 179 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | public function getAccessToken(string $token, string $verifier, string $tokenSecret = null):Token { |
197 | 197 | $this->tokenSecret = $tokenSecret; |
198 | 198 | |
199 | - if(empty($this->tokenSecret)){ |
|
199 | + if (empty($this->tokenSecret)) { |
|
200 | 200 | $this->tokenSecret = $this->storage->getAccessToken($this->serviceName)->requestTokenSecret; |
201 | 201 | } |
202 | 202 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | $parameters['oauth_signature'] = $this->getSignature($url, array_merge($params ?? [], $parameters), $method); |
234 | 234 | |
235 | - if(isset($params['oauth_session_handle'])){ |
|
235 | + if (isset($params['oauth_session_handle'])) { |
|
236 | 236 | $parameters['oauth_session_handle'] = $params['oauth_session_handle']; |
237 | 237 | unset($params['oauth_session_handle']); |
238 | 238 | } |