@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\Core\OAuth1Provider; |
16 | 16 | |
17 | -class OAuth1Testprovider extends OAuth1Provider{ |
|
17 | +class OAuth1Testprovider extends OAuth1Provider { |
|
18 | 18 | |
19 | 19 | protected $apiURL = 'https://api.example.com'; |
20 | 20 | protected $requestTokenURL = 'https://example.com/oauth/request_token'; |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\HTTP\MagicAPI\EndpointMap; |
16 | 16 | |
17 | -class TestEndpoints extends EndpointMap{ |
|
17 | +class TestEndpoints extends EndpointMap { |
|
18 | 18 | |
19 | 19 | protected $test = [ |
20 | 20 | 'path' => '/test/%1$s', |
@@ -24,7 +24,7 @@ |
||
24 | 24 | protected $authURL = 'https://example.com/oauth2/authorize'; |
25 | 25 | protected $accessTokenURL = 'https://example.com/oauth2/token'; |
26 | 26 | protected $userRevokeURL = 'https://account.example.com/apps/'; |
27 | - protected $endpointMap = TestEndpoints::class; |
|
27 | + protected $endpointMap = TestEndpoints::class; |
|
28 | 28 | protected $authHeaders = ['foo' => 'bar']; |
29 | 29 | protected $apiHeaders = ['foo' => 'bar']; |
30 | 30 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use DateTime; |
17 | 17 | use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface}; |
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 |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ->withHeader('Authorization', 'OAuth '.Psr7\build_http_query($params, true, ', ', '"')); |
60 | 60 | ; |
61 | 61 | |
62 | - foreach($this->authHeaders as $header => $value){ |
|
62 | + foreach ($this->authHeaders as $header => $value) { |
|
63 | 63 | $request = $request->withAddedHeader($header, $value); |
64 | 64 | } |
65 | 65 | |
@@ -76,17 +76,17 @@ discard block |
||
76 | 76 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
77 | 77 | parse_str($response->getBody()->getContents(), $data); |
78 | 78 | |
79 | - if(!$data || !is_array($data)){ |
|
79 | + if (!$data || !is_array($data)) { |
|
80 | 80 | throw new ProviderException('unable to parse token response'); |
81 | 81 | } |
82 | - elseif(isset($data['error'])){ |
|
82 | + elseif (isset($data['error'])) { |
|
83 | 83 | throw new ProviderException('error retrieving access token: '.$data['error']); |
84 | 84 | } |
85 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
85 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
86 | 86 | throw new ProviderException('invalid token'); |
87 | 87 | } |
88 | 88 | |
89 | - if($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')){ |
|
89 | + if ($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')) { |
|
90 | 90 | throw new ProviderException('oauth callback unconfirmed'); |
91 | 91 | } |
92 | 92 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
132 | 132 | $parseURL = parse_url($url); |
133 | 133 | |
134 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
134 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
135 | 135 | throw new ProviderException('getSignature: invalid url'); |
136 | 136 | } |
137 | 137 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $signatureParams = array_merge($query, $params); |
141 | 141 | |
142 | - if(isset($signatureParams['oauth_signature'])){ |
|
142 | + if (isset($signatureParams['oauth_signature'])) { |
|
143 | 143 | unset($signatureParams['oauth_signature']); |
144 | 144 | } |
145 | 145 |
@@ -78,11 +78,9 @@ |
||
78 | 78 | |
79 | 79 | if(!$data || !is_array($data)){ |
80 | 80 | throw new ProviderException('unable to parse token response'); |
81 | - } |
|
82 | - elseif(isset($data['error'])){ |
|
81 | + } elseif(isset($data['error'])){ |
|
83 | 82 | throw new ProviderException('error retrieving access token: '.$data['error']); |
84 | - } |
|
85 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
83 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
86 | 84 | throw new ProviderException('invalid token'); |
87 | 85 | } |
88 | 86 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @method array setState(array $params) |
21 | 21 | * @method \chillerlan\OAuth\Core\OAuth2Interface checkState(string $state = null) |
22 | 22 | */ |
23 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
23 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @var int |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public function getAuthURL(array $params = null, array $scopes = null):UriInterface{ |
57 | 57 | $params = $params ?? []; |
58 | 58 | |
59 | - if(isset($params['client_secret'])){ |
|
59 | + if (isset($params['client_secret'])) { |
|
60 | 60 | unset($params['client_secret']); |
61 | 61 | } |
62 | 62 | |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | 'type' => 'web_server', |
68 | 68 | ]); |
69 | 69 | |
70 | - if($scopes !== null){ |
|
70 | + if ($scopes !== null) { |
|
71 | 71 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
72 | 72 | } |
73 | 73 | |
74 | - if($this instanceof CSRFToken){ |
|
74 | + if ($this instanceof CSRFToken) { |
|
75 | 75 | $params = $this->setState($params); |
76 | 76 | } |
77 | 77 | |
@@ -87,19 +87,19 @@ discard block |
||
87 | 87 | protected function parseTokenResponse(ResponseInterface $response):AccessToken{ |
88 | 88 | $data = json_decode($response->getBody()->getContents(), true); |
89 | 89 | |
90 | - if(!is_array($data)){ |
|
90 | + if (!is_array($data)) { |
|
91 | 91 | throw new ProviderException('unable to parse token response'); |
92 | 92 | } |
93 | 93 | |
94 | - foreach(['error_description', 'error'] as $field){ |
|
94 | + foreach (['error_description', 'error'] as $field) { |
|
95 | 95 | |
96 | - if(isset($data[$field])){ |
|
96 | + if (isset($data[$field])) { |
|
97 | 97 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
98 | 98 | } |
99 | 99 | |
100 | 100 | } |
101 | 101 | |
102 | - if(!isset($data['access_token'])){ |
|
102 | + if (!isset($data['access_token'])) { |
|
103 | 103 | throw new ProviderException('token missing'); |
104 | 104 | } |
105 | 105 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function getAccessToken(string $code, string $state = null):AccessToken{ |
127 | 127 | |
128 | - if($this instanceof CSRFToken){ |
|
128 | + if ($this instanceof CSRFToken) { |
|
129 | 129 | $this->checkState($state); |
130 | 130 | } |
131 | 131 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | ->withHeader('Content-Type', 'application/x-www-form-urlencoded') |
143 | 143 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))); |
144 | 144 | |
145 | - foreach($this->authHeaders as $header => $value){ |
|
145 | + foreach ($this->authHeaders as $header => $value) { |
|
146 | 146 | $request = $request->withHeader($header, $value); |
147 | 147 | } |
148 | 148 | |
@@ -162,15 +162,15 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{ |
164 | 164 | |
165 | - if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){ |
|
165 | + if (array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)) { |
|
166 | 166 | $request = $request->withHeader('Authorization', $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken); |
167 | 167 | } |
168 | - elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){ |
|
168 | + elseif (array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)) { |
|
169 | 169 | $uri = Psr7\merge_query((string)$request->getUri(), [$this::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]); |
170 | 170 | |
171 | 171 | $request = $request->withUri($this->uriFactory->createUri($uri)); |
172 | 172 | } |
173 | - else{ |
|
173 | + else { |
|
174 | 174 | throw new ProviderException('invalid auth type'); |
175 | 175 | } |
176 | 176 |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
123 | 123 | */ |
124 | - public function __construct(HttpClient $http, OAuthStorageInterface $storage, SettingsContainerInterface $options){ |
|
124 | + public function __construct(HttpClient $http, OAuthStorageInterface $storage, SettingsContainerInterface $options) { |
|
125 | 125 | $this->http = $http; |
126 | 126 | $this->storage = $storage; |
127 | 127 | $this->options = $options; |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | |
134 | 134 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
135 | 135 | |
136 | - if(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
136 | + if (!empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
137 | 137 | $this->endpoints = new $this->endpointMap; |
138 | 138 | |
139 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
139 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
140 | 140 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
141 | 141 | } |
142 | 142 | |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return string|null |
151 | 151 | */ |
152 | - public function __get(string $name):?string{ |
|
152 | + public function __get(string $name): ?string{ |
|
153 | 153 | |
154 | - if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)){ |
|
154 | + if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)) { |
|
155 | 155 | return null; |
156 | 156 | } |
157 | 157 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public function __call(string $name, array $arguments):ResponseInterface{ |
209 | 209 | |
210 | - if(!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)){ |
|
210 | + if (!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)) { |
|
211 | 211 | throw new ApiClientException('endpoint not found'); |
212 | 212 | } |
213 | 213 | |
@@ -220,21 +220,21 @@ discard block |
||
220 | 220 | $path_elements = $m['path_elements'] ?? []; |
221 | 221 | $params_in_url = count($path_elements); |
222 | 222 | $params = $arguments[$params_in_url] ?? []; |
223 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
223 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
224 | 224 | |
225 | - if($params_in_url > 0){ |
|
225 | + if ($params_in_url > 0) { |
|
226 | 226 | |
227 | - if(count($urlparams) < $params_in_url){ |
|
227 | + if (count($urlparams) < $params_in_url) { |
|
228 | 228 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
229 | 229 | } |
230 | 230 | |
231 | 231 | $endpoint = sprintf($endpoint, ...$urlparams); |
232 | 232 | } |
233 | 233 | |
234 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
234 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
235 | 235 | $body = $arguments[$params_in_url + 1] ?? $params; |
236 | 236 | |
237 | - if($params === $body){ |
|
237 | + if ($params === $body) { |
|
238 | 238 | $params = []; |
239 | 239 | } |
240 | 240 | |
@@ -281,32 +281,32 @@ discard block |
||
281 | 281 | $token = $this->storage->getAccessToken($this->serviceName); |
282 | 282 | |
283 | 283 | // attempt to refresh an expired token |
284 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
284 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
285 | 285 | $token = $this->refreshAccessToken($token); |
286 | 286 | } |
287 | 287 | |
288 | 288 | $request = $this->requestFactory |
289 | 289 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? [])); |
290 | 290 | |
291 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
291 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
292 | 292 | $request = $request->withAddedHeader($header, $value); |
293 | 293 | } |
294 | 294 | |
295 | 295 | $request = $this->getRequestAuthorization($request, $token); |
296 | 296 | |
297 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
297 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
298 | 298 | $contentType = strtolower($request->getHeaderLine('content-type')); |
299 | 299 | |
300 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
300 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
301 | 301 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
302 | 302 | } |
303 | - elseif($contentType === 'application/json'){ |
|
303 | + elseif ($contentType === 'application/json') { |
|
304 | 304 | $body = $this->streamFactory->createStream(json_encode($body)); |
305 | 305 | } |
306 | 306 | |
307 | 307 | } |
308 | 308 | |
309 | - if($body instanceof StreamInterface){ |
|
309 | + if ($body instanceof StreamInterface) { |
|
310 | 310 | $request = $request->withBody($body); |
311 | 311 | } |
312 | 312 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | |
18 | -class SessionStorage extends OAuthStorageAbstract{ |
|
18 | +class SessionStorage extends OAuthStorageAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var bool |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
39 | 39 | */ |
40 | - public function __construct(SettingsContainerInterface $options = null){ |
|
40 | + public function __construct(SettingsContainerInterface $options = null) { |
|
41 | 41 | parent::__construct($options); |
42 | 42 | |
43 | 43 | $this->sessionVar = $this->options->sessionTokenVar; |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | |
46 | 46 | // Determine if the session has started. |
47 | 47 | // @link http://stackoverflow.com/a/18542272/1470961 |
48 | - if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){ |
|
48 | + if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) { |
|
49 | 49 | session_start(); |
50 | 50 | } |
51 | 51 | |
52 | - if(!isset($_SESSION[$this->sessionVar])){ |
|
52 | + if (!isset($_SESSION[$this->sessionVar])) { |
|
53 | 53 | $_SESSION[$this->sessionVar] = []; |
54 | 54 | } |
55 | 55 | |
56 | - if(!isset($_SESSION[$this->stateVar])){ |
|
56 | + if (!isset($_SESSION[$this->stateVar])) { |
|
57 | 57 | $_SESSION[$this->stateVar] = []; |
58 | 58 | } |
59 | 59 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @codeCoverageIgnore |
66 | 66 | */ |
67 | - public function __destruct(){ |
|
68 | - if($this->options->sessionStart){ |
|
67 | + public function __destruct() { |
|
68 | + if ($this->options->sessionStart) { |
|
69 | 69 | session_write_close(); |
70 | 70 | } |
71 | 71 | } |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
80 | 80 | $token = $token->toJSON(); |
81 | 81 | |
82 | - if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
|
82 | + if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) { |
|
83 | 83 | $_SESSION[$this->sessionVar][$service] = $token; |
84 | 84 | } |
85 | - else{ |
|
85 | + else { |
|
86 | 86 | $_SESSION[$this->sessionVar] = [$service => $token]; |
87 | 87 | } |
88 | 88 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function getAccessToken(string $service):AccessToken{ |
99 | 99 | |
100 | - if($this->hasAccessToken($service)){ |
|
100 | + if ($this->hasAccessToken($service)) { |
|
101 | 101 | return (new AccessToken)->fromJSON($_SESSION[$this->sessionVar][$service]); |
102 | 102 | } |
103 | 103 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
122 | 122 | |
123 | - if(array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
123 | + if (array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
124 | 124 | unset($_SESSION[$this->sessionVar][$service]); |
125 | 125 | } |
126 | 126 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function clearAllAccessTokens():OAuthStorageInterface{ |
134 | 134 | |
135 | - foreach(array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
135 | + foreach (array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
136 | 136 | unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor |
137 | 137 | } |
138 | 138 | |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function storeCSRFState(string $service, string $state):OAuthStorageInterface{ |
151 | 151 | |
152 | - if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
|
152 | + if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) { |
|
153 | 153 | $_SESSION[$this->stateVar][$service] = $state; |
154 | 154 | } |
155 | - else{ |
|
155 | + else { |
|
156 | 156 | $_SESSION[$this->stateVar] = [$service => $state]; |
157 | 157 | } |
158 | 158 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function getCSRFState(string $service):string{ |
169 | 169 | |
170 | - if($this->hasCSRFState($service)){ |
|
170 | + if ($this->hasCSRFState($service)) { |
|
171 | 171 | return $_SESSION[$this->stateVar][$service]; |
172 | 172 | } |
173 | 173 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
192 | 192 | |
193 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
193 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
194 | 194 | unset($_SESSION[$this->stateVar][$service]); |
195 | 195 | } |
196 | 196 |