Passed
Push — master ( ced49e...76b2bf )
by smiley
01:37
created
src/Core/CSRFToken.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,6 +18,6 @@
 block discarded – undo
18 18
  * @method checkState(string $state = null):void
19 19
  * @method setState(array $params):array
20 20
  */
21
-interface CSRFToken{
21
+interface CSRFToken {
22 22
 
23 23
 }
Please login to merge, or discard this patch.
src/Core/OAuth2Provider.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use chillerlan\HTTP\Psr7;
18 18
 use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface};
19 19
 
20
-abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
20
+abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface {
21 21
 
22 22
 	/**
23 23
 	 * @var int
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
64 64
 			'type'          => 'web_server',
65 65
 		]);
66 66
 
67
-		if($scopes !== null){
67
+		if ($scopes !== null) {
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
 block discarded – undo
84 84
 	protected function parseTokenResponse(ResponseInterface $response):AccessToken{
85 85
 		$data = \json_decode(Psr7\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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 = Psr7\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,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	public function getClientCredentialsToken(array $scopes = null):AccessToken{
184 184
 		$params = ['grant_type' => 'client_credentials'];
185 185
 
186
-		if($scopes !== null){
186
+		if ($scopes !== null) {
187 187
 			$params['scope'] = \implode($this->scopesDelimiter, $scopes);
188 188
 		}
189 189
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 			->withBody($this->streamFactory->createStream(\http_build_query($params, '', '&', \PHP_QUERY_RFC1738)))
196 196
 		;
197 197
 
198
-		foreach($this->authHeaders as $header => $value){
198
+		foreach ($this->authHeaders as $header => $value) {
199 199
 			$request = $request->withAddedHeader($header, $value);
200 200
 		}
201 201
 
@@ -214,15 +214,15 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	public function refreshAccessToken(AccessToken $token = null):AccessToken{
216 216
 
217
-		if($token === null){
217
+		if ($token === null) {
218 218
 			$token = $this->storage->getAccessToken($this->serviceName);
219 219
 		}
220 220
 
221 221
 		$refreshToken = $token->refreshToken;
222 222
 
223
-		if(empty($refreshToken)){
223
+		if (empty($refreshToken)) {
224 224
 
225
-			if(!$this instanceof AccessTokenForRefresh){
225
+			if (!$this instanceof AccessTokenForRefresh) {
226 226
 				throw new ProviderException(\sprintf('no refresh token available, token expired [%s]', \date('Y-m-d h:i:s A', $token->expires)));
227 227
 			}
228 228
 
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 			->withBody($this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)))
245 245
 		;
246 246
 
247
-		foreach($this->authHeaders as $header => $value){
247
+		foreach ($this->authHeaders as $header => $value) {
248 248
 			$request = $request->withAddedHeader($header, $value);
249 249
 		}
250 250
 
251 251
 		$newToken = $this->parseTokenResponse($this->http->sendRequest($request));
252 252
 
253
-		if(empty($newToken->refreshToken)){
253
+		if (empty($newToken->refreshToken)) {
254 254
 			$newToken->refreshToken = $refreshToken;
255 255
 		}
256 256
 
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 */
268 268
 	protected function checkState(string $state = null):void{
269 269
 
270
-		if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){
270
+		if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) {
271 271
 			throw new ProviderException('invalid state for '.$this->serviceName);
272 272
 		}
273 273
 
274 274
 		$knownState = $this->storage->getCSRFState($this->serviceName);
275 275
 
276
-		if(!\hash_equals($knownState, $state)){
276
+		if (!\hash_equals($knownState, $state)) {
277 277
 			throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state);
278 278
 		}
279 279
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	protected function setState(array $params):array{
288 288
 
289
-		if(!isset($params['state'])){
289
+		if (!isset($params['state'])) {
290 290
 			$params['state'] = \sha1(\random_bytes(256));
291 291
 		}
292 292
 
Please login to merge, or discard this patch.
src/Core/OAuthInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
  * @property string                                         $serviceName
27 27
  * @property string                                         $userRevokeURL
28 28
  */
29
-interface OAuthInterface{
29
+interface OAuthInterface {
30 30
 
31 31
 	/**
32 32
 	 * @param array $params
Please login to merge, or discard this patch.