Completed
Push — master ( 970893...bdcfe0 )
by smiley
03:30
created
src/Core/OAuth2Interface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use Psr\Http\Message\UriInterface;
16 16
 
17
-interface OAuth2Interface extends OAuthInterface{
17
+interface OAuth2Interface extends OAuthInterface {
18 18
 
19 19
 	const AUTH_METHOD_HEADER = 1;
20 20
 	const AUTH_METHOD_QUERY  = 2;
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
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
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
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	public function getAuthURL(array $params = null, array $scopes = null):UriInterface{
61 61
 		$params = $params ?? [];
62 62
 
63
-		if(isset($params['client_secret'])){
63
+		if (isset($params['client_secret'])) {
64 64
 			unset($params['client_secret']);
65 65
 		}
66 66
 
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 			'type'          => 'web_server',
72 72
 		]);
73 73
 
74
-		if(!empty($scopes)){
74
+		if (!empty($scopes)) {
75 75
 			$params['scope'] = implode($this->scopesDelimiter, $scopes);
76 76
 		}
77 77
 
78
-		if($this instanceof CSRFToken){
78
+		if ($this instanceof CSRFToken) {
79 79
 			$params = $this->setState($params);
80 80
 		}
81 81
 
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 	protected function parseTokenResponse(ResponseInterface $response):AccessToken{
92 92
 		$data = json_decode(decompress_content($response), true); // silly amazon...
93 93
 
94
-		if(!is_array($data)){
94
+		if (!is_array($data)) {
95 95
 			throw new ProviderException('unable to parse token response');
96 96
 		}
97 97
 
98
-		foreach(['error_description', 'error'] as $field){
98
+		foreach (['error_description', 'error'] as $field) {
99 99
 
100
-			if(isset($data[$field])){
100
+			if (isset($data[$field])) {
101 101
 				throw new ProviderException('error retrieving access token: "'.$data[$field].'"');
102 102
 			}
103 103
 
104 104
 		}
105 105
 
106
-		if(!isset($data['access_token'])){
106
+		if (!isset($data['access_token'])) {
107 107
 			throw new ProviderException('token missing');
108 108
 		}
109 109
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 */
127 127
 	public function getAccessToken(string $code, string $state = null):AccessToken{
128 128
 
129
-		if($this instanceof CSRFToken){
129
+		if ($this instanceof CSRFToken) {
130 130
 			$this->checkState($state);
131 131
 		}
132 132
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			->withHeader('Accept-Encoding', 'identity')
145 145
 			->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)));
146 146
 
147
-		foreach($this->authHeaders as $header => $value){
147
+		foreach ($this->authHeaders as $header => $value) {
148 148
 			$request = $request->withHeader($header, $value);
149 149
 		}
150 150
 
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
162 162
 
163
-		if($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER){
163
+		if ($this->authMethod === OAuth2Interface::AUTH_METHOD_HEADER) {
164 164
 			return $request->withHeader('Authorization', $this->authMethodHeader.' '.$token->accessToken);
165 165
 		}
166 166
 
167
-		if($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY){
167
+		if ($this->authMethod === OAuth2Interface::AUTH_METHOD_QUERY) {
168 168
 			$uri = merge_query($request->getUri()->__toString(), [$this->authMethodQuery => $token->accessToken]);
169 169
 
170 170
 			return $request->withUri($this->uriFactory->createUri($uri));
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 	 */
180 180
 	public function getClientCredentialsToken(array $scopes = null):AccessToken{
181 181
 
182
-		if(!$this instanceof ClientCredentials){
182
+		if (!$this instanceof ClientCredentials) {
183 183
 			throw new ProviderException('client credentials token not supported');
184 184
 		}
185 185
 
186 186
 		$params = ['grant_type' => 'client_credentials'];
187 187
 
188
-		if($scopes !== null){
188
+		if ($scopes !== null) {
189 189
 			$params['scope'] = implode($this->scopesDelimiter, $scopes);
190 190
 		}
191 191
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 			->withBody($this->streamFactory->createStream(http_build_query($params, '', '&', PHP_QUERY_RFC1738)))
198 198
 		;
199 199
 
200
-		foreach($this->authHeaders as $header => $value){
200
+		foreach ($this->authHeaders as $header => $value) {
201 201
 			$request = $request->withAddedHeader($header, $value);
202 202
 		}
203 203
 
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	public function refreshAccessToken(AccessToken $token = null):AccessToken{
216 216
 
217
-		if(!$this instanceof TokenRefresh){
217
+		if (!$this instanceof TokenRefresh) {
218 218
 			throw new ProviderException('token refresh not supported');
219 219
 		}
220 220
 
221
-		if($token === null){
221
+		if ($token === null) {
222 222
 			$token = $this->storage->getAccessToken($this->serviceName);
223 223
 		}
224 224
 
225 225
 		$refreshToken = $token->refreshToken;
226 226
 
227
-		if(empty($refreshToken)){
227
+		if (empty($refreshToken)) {
228 228
 			throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires)));
229 229
 		}
230 230
 
@@ -243,13 +243,13 @@  discard block
 block discarded – undo
243 243
 			->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)))
244 244
 		;
245 245
 
246
-		foreach($this->authHeaders as $header => $value){
246
+		foreach ($this->authHeaders as $header => $value) {
247 247
 			$request = $request->withAddedHeader($header, $value);
248 248
 		}
249 249
 
250 250
 		$newToken = $this->parseTokenResponse($this->http->sendRequest($request));
251 251
 
252
-		if(empty($newToken->refreshToken)){
252
+		if (empty($newToken->refreshToken)) {
253 253
 			$newToken->refreshToken = $refreshToken;
254 254
 		}
255 255
 
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
 	 */
267 267
 	protected function checkState(string $state = null):void{
268 268
 
269
-		if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){
269
+		if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) {
270 270
 			throw new ProviderException('invalid state for '.$this->serviceName);
271 271
 		}
272 272
 
273 273
 		$knownState = $this->storage->getCSRFState($this->serviceName);
274 274
 
275
-		if(!hash_equals($knownState, $state)){
275
+		if (!hash_equals($knownState, $state)) {
276 276
 			throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state);
277 277
 		}
278 278
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 	 */
286 286
 	protected function setState(array $params):array{
287 287
 
288
-		if(!isset($params['state'])){
288
+		if (!isset($params['state'])) {
289 289
 			$params['state'] = sha1(random_bytes(256));
290 290
 		}
291 291
 
Please login to merge, or discard this patch.