@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth; |
14 | 14 | |
15 | -trait OAuthOptionsTrait{ |
|
15 | +trait OAuthOptionsTrait { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @var string |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | /** |
77 | 77 | * @var string |
78 | 78 | */ |
79 | - protected $dbLabelFormat = '%1$s@%2$s'; // user@service |
|
79 | + protected $dbLabelFormat = '%1$s@%2$s'; // user@service |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @var int|string |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\OAuthException; |
16 | 16 | |
17 | -class TokenStorageException extends OAuthException{} |
|
17 | +class TokenStorageException extends OAuthException {} |
@@ -83,8 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
85 | 85 | $_SESSION[$this->sessionVar][$service] = $token; |
86 | - } |
|
87 | - else{ |
|
86 | + } else{ |
|
88 | 87 | $_SESSION[$this->sessionVar] = [$service => $token]; |
89 | 88 | } |
90 | 89 | |
@@ -153,8 +152,7 @@ discard block |
||
153 | 152 | |
154 | 153 | if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
155 | 154 | $_SESSION[$this->stateVar][$service] = $state; |
156 | - } |
|
157 | - else{ |
|
155 | + } else{ |
|
158 | 156 | $_SESSION[$this->stateVar] = [$service => $state]; |
159 | 157 | } |
160 | 158 |
@@ -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 |
@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth; |
14 | 14 | |
15 | -class OAuthException extends \Exception{} |
|
15 | +class OAuthException extends \Exception {} |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @property int $expires |
32 | 32 | * @property string $provider |
33 | 33 | */ |
34 | -class Token implements ContainerInterface{ |
|
34 | +class Token implements ContainerInterface { |
|
35 | 35 | use MemzeroDestructorTrait, Container{ |
36 | 36 | __construct as constructContainer; |
37 | 37 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @param array|null $properties |
100 | 100 | */ |
101 | - public function __construct(array $properties = null){ |
|
101 | + public function __construct(array $properties = null) { |
|
102 | 102 | $this->constructContainer($properties); |
103 | 103 | |
104 | 104 | $this->setExpiry($this->expires); |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - public function __set(string $property, $value){ |
|
115 | + public function __set(string $property, $value) { |
|
116 | 116 | |
117 | - if(property_exists($this, $property)){ |
|
117 | + if (property_exists($this, $property)) { |
|
118 | 118 | $property === 'expires' |
119 | 119 | ? $this->setExpiry($value) |
120 | 120 | : $this->{$property} = $value; |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | public function setExpiry(int $expires = null):Token{ |
131 | 131 | $now = time(); |
132 | 132 | |
133 | - if($expires!== null){ |
|
134 | - $expires = intval($expires); |
|
133 | + if ($expires !== null) { |
|
134 | + $expires = intval($expires); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | $this->expires = $this::EOL_UNKNOWN; |
138 | 138 | |
139 | - if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
|
139 | + if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) { |
|
140 | 140 | $this->expires = $this::EOL_NEVER_EXPIRES; |
141 | 141 | } |
142 | - elseif($expires > $now){ |
|
142 | + elseif ($expires > $now) { |
|
143 | 143 | $this->expires = $expires; |
144 | 144 | } |
145 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
145 | + elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) { |
|
146 | 146 | $this->expires = $now + $expires; |
147 | 147 | } |
148 | 148 |
@@ -138,11 +138,9 @@ |
||
138 | 138 | |
139 | 139 | if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
140 | 140 | $this->expires = $this::EOL_NEVER_EXPIRES; |
141 | - } |
|
142 | - elseif($expires > $now){ |
|
141 | + } elseif($expires > $now){ |
|
143 | 142 | $this->expires = $expires; |
144 | - } |
|
145 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
143 | + } elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
146 | 144 | $this->expires = $now + $expires; |
147 | 145 | } |
148 | 146 |
@@ -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 |
@@ -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 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @method array setState(array $params) |
27 | 27 | * @method \chillerlan\OAuth\Providers\OAuth2Interface checkState(string $state = null) |
28 | 28 | */ |
29 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
29 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @var int |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | * @param \Psr\Log\LoggerInterface|null $logger |
63 | 63 | * @param array $scopes |
64 | 64 | */ |
65 | - public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, LoggerInterface $logger = null, array $scopes = null){ |
|
65 | + public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, LoggerInterface $logger = null, array $scopes = null) { |
|
66 | 66 | parent::__construct($http, $storage, $options, $logger); |
67 | 67 | |
68 | - if($scopes !== null){ |
|
68 | + if ($scopes !== null) { |
|
69 | 69 | $this->scopes = $scopes; |
70 | 70 | } |
71 | 71 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | public function getAuthURL(array $params = null):string{ |
80 | 80 | $params = $this->getAuthURLParams($params ?? []); |
81 | 81 | |
82 | - if($this instanceof CSRFToken){ |
|
82 | + if ($this instanceof CSRFToken) { |
|
83 | 83 | $params = $this->setState($params); |
84 | 84 | } |
85 | 85 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | protected function getAuthURLParams(array $params):array { |
95 | 95 | |
96 | 96 | // this should not be here |
97 | - if(isset($params['client_secret'])){ |
|
97 | + if (isset($params['client_secret'])) { |
|
98 | 98 | unset($params['client_secret']); |
99 | 99 | } |
100 | 100 | |
@@ -116,19 +116,19 @@ discard block |
||
116 | 116 | protected function parseTokenResponse(HTTPResponseInterface $response):Token{ |
117 | 117 | $data = $response->json_array; |
118 | 118 | |
119 | - if(!is_array($data)){ |
|
119 | + if (!is_array($data)) { |
|
120 | 120 | throw new ProviderException('unable to parse token response'); |
121 | 121 | } |
122 | 122 | |
123 | - foreach(['error_description', 'error'] as $field){ |
|
123 | + foreach (['error_description', 'error'] as $field) { |
|
124 | 124 | |
125 | - if(isset($data[$field])){ |
|
125 | + if (isset($data[$field])) { |
|
126 | 126 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
127 | 127 | } |
128 | 128 | |
129 | 129 | } |
130 | 130 | |
131 | - if(!isset($data['access_token'])){ |
|
131 | + if (!isset($data['access_token'])) { |
|
132 | 132 | throw new ProviderException('token missing'); |
133 | 133 | } |
134 | 134 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function getAccessToken(string $code, string $state = null):Token{ |
156 | 156 | |
157 | - if($this instanceof CSRFToken){ |
|
157 | + if ($this instanceof CSRFToken) { |
|
158 | 158 | $this->checkState($state); |
159 | 159 | } |
160 | 160 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $token = $this->storage->getAccessToken($this->serviceName); |
209 | 209 | |
210 | 210 | // attempt to refresh an expired token |
211 | - if($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
211 | + if ($this->options->tokenAutoRefresh && $this instanceof TokenRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
212 | 212 | $token = $this->refreshAccessToken($token); |
213 | 213 | } |
214 | 214 | |
@@ -217,15 +217,15 @@ discard block |
||
217 | 217 | $params = array_merge($query, $params ?? []); |
218 | 218 | $headers = $headers ?? []; |
219 | 219 | |
220 | - if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){ |
|
220 | + if (array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)) { |
|
221 | 221 | $headers = array_merge($headers, [ |
222 | 222 | 'Authorization' => $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken, |
223 | 223 | ]); |
224 | 224 | } |
225 | - elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){ |
|
225 | + elseif (array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)) { |
|
226 | 226 | $params[$this::AUTH_METHODS_QUERY[$this->authMethod]] = $token->accessToken; |
227 | 227 | } |
228 | - else{ |
|
228 | + else { |
|
229 | 229 | throw new ProviderException('invalid auth type'); |
230 | 230 | } |
231 | 231 |
@@ -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 |