@@ -359,7 +359,7 @@ |
||
359 | 359 | $getJWT = (isset($options['getJWT']) && is_bool($options['getJWT'])) |
360 | 360 | ? $options['getJWT'] : true; |
361 | 361 | |
362 | - $getSecretAppend = (isset($options['secret']) && ($options['secret'] == 'append') ) |
|
362 | + $getSecretAppend = (isset($options['secret']) && ($options['secret'] == 'append')) |
|
363 | 363 | ? $options['secret'] : false; |
364 | 364 | |
365 | 365 | return (new user\user) |
@@ -65,7 +65,7 @@ |
||
65 | 65 | */ |
66 | 66 | public static function payload(array $payloadObject = []) |
67 | 67 | { |
68 | - if( isset($payloadObject['scope']) && $payloadObject['scope'] == 'anonymous' ) { |
|
68 | + if (isset($payloadObject['scope']) && $payloadObject['scope'] == 'anonymous') { |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 |
@@ -50,7 +50,7 @@ |
||
50 | 50 | */ |
51 | 51 | $payloadObject = $cipher->jsonDecode($cipher->decode($jwtPayload)); |
52 | 52 | |
53 | - if( $this->key == 'payloadOnly' ) { |
|
53 | + if ($this->key == 'payloadOnly') { |
|
54 | 54 | return $payloadObject; |
55 | 55 | } |
56 | 56 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Check if a custom scope is set |
65 | 65 | */ |
66 | - if( isset($this->header->getMethod()->data['scope']) && |
|
66 | + if (isset($this->header->getMethod()->data['scope']) && |
|
67 | 67 | ($this->header->getMethod()->data['scope'] == 'anonymous') |
68 | 68 | ) { |
69 | 69 | $this->grantAccess = true; |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | ->decode() |
102 | 102 | ; |
103 | 103 | |
104 | - if( isset($decoded['sub']) && !empty($decoded['sub']) ) { |
|
104 | + if (isset($decoded['sub']) && !empty($decoded['sub'])) { |
|
105 | 105 | |
106 | 106 | $this->user = (object) (new user\user) |
107 | 107 | ->setOptions($this->getOptions()) |
108 | 108 | ->load($decoded['sub'], ['refreshToken' => true]) |
109 | 109 | ; |
110 | 110 | |
111 | - if ( !empty($this->user) ) { |
|
111 | + if (!empty($this->user)) { |
|
112 | 112 | $jwt = new auth\jwt; |
113 | 113 | $decoded = $jwt |
114 | 114 | ->setOptions($this->getOptions()) |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ->decode() |
118 | 118 | ; |
119 | 119 | } |
120 | - }else{ |
|
120 | + } else { |
|
121 | 121 | |
122 | 122 | $this->header->unauthorised(); |
123 | 123 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * [$user Check user account] |
128 | 128 | * @var [object] |
129 | 129 | */ |
130 | - if ( (isset($decoded['sub']) && !empty($decoded['sub'])) && !$this->user ) { |
|
130 | + if ((isset($decoded['sub']) && !empty($decoded['sub'])) && !$this->user) { |
|
131 | 131 | $this->user = (object) (new user\user) |
132 | 132 | ->setOptions($this->getOptions()) |
133 | 133 | ->load($decoded['sub'], ['refreshToken' => true]) |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public function user() |
150 | 150 | { |
151 | - if( $this->isGrantType() ) { |
|
151 | + if ($this->isGrantType()) { |
|
152 | 152 | return (object) [ |
153 | 153 | 'uid' => -1, |
154 | 154 | 'account_id' => 0, |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - if( isset($this->header->getMethod()->data['scope']) && |
|
180 | + if (isset($this->header->getMethod()->data['scope']) && |
|
181 | 181 | ($this->header->getMethod()->data['scope'] == 'anonymous') |
182 | 182 | ) { |
183 | 183 | return; |
@@ -35,7 +35,7 @@ |
||
35 | 35 | */ |
36 | 36 | public function apiKeyGenerate($length = 32) |
37 | 37 | { |
38 | - $randInt = microtime().rand(1000, 9999); |
|
38 | + $randInt = microtime() . rand(1000, 9999); |
|
39 | 39 | $messageDigest = md5($randInt); |
40 | 40 | return implode( |
41 | 41 | '-', |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function updateAccount($properties) |
132 | 132 | { |
133 | - if( is_array($properties) ) { |
|
133 | + if (is_array($properties)) { |
|
134 | 134 | $properties = (object) $properties; //json_decode(json_encode($properties)); |
135 | 135 | } |
136 | 136 | |
137 | - if( !isset($properties->update) || |
|
137 | + if (!isset($properties->update) || |
|
138 | 138 | !isset($properties->where) || |
139 | 139 | (isset($properties->update) && !is_array($properties->update)) || |
140 | 140 | (isset($properties->where) && !is_array($properties->where)) |
@@ -161,16 +161,16 @@ discard block |
||
161 | 161 | * @var [type] |
162 | 162 | */ |
163 | 163 | foreach ($properties->update as $u => $update) { |
164 | - if( !in_array($u, $allowedFileds) ) { |
|
164 | + if (!in_array($u, $allowedFileds)) { |
|
165 | 165 | unset($properties->update[$u]); |
166 | - }else{ |
|
166 | + } else { |
|
167 | 167 | $set .= $u . ' = :' . $u . ','; |
168 | 168 | $binds[$u] = $update; |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | $set = rtrim($set, ','); |
173 | - $where = key($properties->where) . ' = ' . $properties->where[key($properties->where)]; |
|
173 | + $where = key($properties->where) . ' = ' . $properties->where[key($properties->where)]; |
|
174 | 174 | |
175 | 175 | return $this->DB()-> |
176 | 176 | query( |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $options = $this->getOptions(); |
215 | 215 | $skipValidatation = false; |
216 | 216 | |
217 | - if( isset($options['validate']) && $options['validate'] == false ) { |
|
217 | + if (isset($options['validate']) && $options['validate'] == false) { |
|
218 | 218 | $skipValidatation = true; |
219 | 219 | } |
220 | 220 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | break; |
231 | 231 | |
232 | 232 | case 'mail': |
233 | - if( !filter_var($property, FILTER_VALIDATE_EMAIL) && !$skipValidatation) { |
|
233 | + if (!filter_var($property, FILTER_VALIDATE_EMAIL) && !$skipValidatation) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | 236 | $this->mail = $property; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | 'MESSAGE' => $message, |
171 | 171 | ), JSON_PRETTY_PRINT); |
172 | 172 | |
173 | - if( isset($options['errors']) && $options['errors'] == 'catchAll' ) { |
|
173 | + if (isset($options['errors']) && $options['errors'] == 'catchAll') { |
|
174 | 174 | throw new \Exception($eMessage, 1); |
175 | 175 | } |
176 | 176 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | 'MESSAGE' => $message, |
186 | 186 | ), JSON_PRETTY_PRINT); |
187 | 187 | |
188 | - if( isset($options['errors']) && $options['errors'] == 'catchAll' ) { |
|
188 | + if (isset($options['errors']) && $options['errors'] == 'catchAll') { |
|
189 | 189 | throw new \Exception($eMessage, 1); |
190 | 190 | } |
191 | 191 |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | foreach ($headers_list as $index => $headValue) { |
190 | 190 | @list($key, $value) = explode(": ", $headValue); |
191 | 191 | |
192 | - if (!is_null($key) && !is_null($value) ) { |
|
192 | + if (!is_null($key) && !is_null($value)) { |
|
193 | 193 | $headers_list[$key] = $value; |
194 | 194 | unset($headers_list[$index]); |
195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $apacheRequestHeaders = apache_request_headers(); |
202 | 202 | } |
203 | 203 | |
204 | - if( is_null($apacheRequestHeaders) || empty($apacheRequestHeaders) ) { |
|
204 | + if (is_null($apacheRequestHeaders) || empty($apacheRequestHeaders)) { |
|
205 | 205 | return []; |
206 | 206 | } |
207 | 207 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | '*', |
260 | 260 | )); |
261 | 261 | |
262 | - if( !array_key_exists('Access-Control-Allow-Methods', $this->getHeaders()) ) { |
|
262 | + if (!array_key_exists('Access-Control-Allow-Methods', $this->getHeaders())) { |
|
263 | 263 | $this->setHeader('Access-Control-Allow-Methods', array( |
264 | 264 | 'GET,POST,OPTIONS', |
265 | 265 | )); |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | ) |
459 | 459 | ); |
460 | 460 | |
461 | - if( empty($account) ) { |
|
461 | + if (empty($account)) { |
|
462 | 462 | $this->unauthorised(); |
463 | 463 | } |
464 | 464 |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | $this->secret = $this->getDefaults()['config']['MASTER_KEY']; |
101 | 101 | |
102 | - if( isset($options['secret']) && $options['secret'] == 'append' ) { |
|
102 | + if (isset($options['secret']) && $options['secret'] == 'append') { |
|
103 | 103 | $this->secretAppend = true; |
104 | 104 | } |
105 | 105 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | \PDO::FETCH_OBJ |
139 | 139 | ); |
140 | 140 | |
141 | - if( $this->secretAppend ) { |
|
141 | + if ($this->secretAppend) { |
|
142 | 142 | $this->secret = $account->secret; |
143 | 143 | } |
144 | 144 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $account->refresh_token = $this->refreshTokenGenerate($account); |
152 | 152 | $sentToken = (new headers\header)->hasBearerToken(); |
153 | 153 | |
154 | - if( $sentToken ) { |
|
154 | + if ($sentToken) { |
|
155 | 155 | /** |
156 | 156 | * [$jwt Decode the JWT] |
157 | 157 | * @var auth\jwt |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ; |
170 | 170 | $absSeconds = ($decoded['exp'] - ($this->timeNow() - $leeway)); |
171 | 171 | |
172 | - if( $absSeconds > 0 ) { |
|
172 | + if ($absSeconds > 0) { |
|
173 | 173 | $account->JWT = $sentToken; |
174 | 174 | } |
175 | 175 | |
@@ -207,21 +207,21 @@ discard block |
||
207 | 207 | public function refreshTokenGenerate($account) |
208 | 208 | { |
209 | 209 | $offset = 86400; |
210 | - $time = ($this->timeNow()+$offset); |
|
210 | + $time = ($this->timeNow() + $offset); |
|
211 | 211 | |
212 | - if( isset($account->refresh_token) && !empty($account->refresh_token) ) { |
|
212 | + if (isset($account->refresh_token) && !empty($account->refresh_token)) { |
|
213 | 213 | $raToken = explode('.', $account->refresh_token); |
214 | - if( !empty($raToken) ) { |
|
214 | + if (!empty($raToken)) { |
|
215 | 215 | $raToken = array_values(array_filter($raToken)); |
216 | - $time = ($raToken[0] <= ($this->timeNow()-$offset) ) ? ($this->timeNow()+$offset) : $raToken[0]; |
|
216 | + $time = ($raToken[0] <= ($this->timeNow() - $offset)) ? ($this->timeNow() + $offset) : $raToken[0]; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | 220 | $cipher = new encoder\cipher; |
221 | - $refreshHash = $account->account_id.':'.$account->secret; |
|
221 | + $refreshHash = $account->account_id . ':' . $account->secret; |
|
222 | 222 | $refreshHash = $cipher->encode($cipher->hash('sha256', $refreshHash, $account->secret)); |
223 | 223 | |
224 | - $refreshHash = $time.'.'.$refreshHash; |
|
224 | + $refreshHash = $time . '.' . $refreshHash; |
|
225 | 225 | $account->refreshToken = $refreshHash; |
226 | 226 | |
227 | 227 | $updateProp = [ |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | /** |
294 | 294 | * Check token expiry |
295 | 295 | */ |
296 | - if($this->checkVal($userPayload['payload'], 'exp') && !$skipExpiry) { |
|
296 | + if ($this->checkVal($userPayload['payload'], 'exp') && !$skipExpiry) { |
|
297 | 297 | return $this->refreshJWT($userPayload); |
298 | 298 | } |
299 | 299 | |
@@ -357,26 +357,26 @@ discard block |
||
357 | 357 | $payload['iat'] = $iat; |
358 | 358 | } |
359 | 359 | if (false !== ($nbf = $this->checkVal($jwtOptions, 'notBeFor'))) { |
360 | - if( strtolower($nbf) == 'issuedat' && isset($payload['iat']) ) { |
|
360 | + if (strtolower($nbf) == 'issuedat' && isset($payload['iat'])) { |
|
361 | 361 | $nbf = $payload['iat'] + 10; |
362 | 362 | } |
363 | 363 | $payload['nbf'] = $nbf; |
364 | 364 | } |
365 | 365 | } |
366 | 366 | |
367 | - if( $refresh && $exp ) { |
|
367 | + if ($refresh && $exp) { |
|
368 | 368 | $refreshPayload = $payload; |
369 | 369 | |
370 | 370 | $offset = $exp - $this->timeNow(); |
371 | 371 | $leeway = ($this->checkVal($this->options['jwt'], 'leeway')) ?: $this->jwt->getLeeway(); |
372 | 372 | |
373 | - $refreshPayload['exp'] = $exp+$offset+$leeway; |
|
373 | + $refreshPayload['exp'] = $exp + $offset + $leeway; |
|
374 | 374 | |
375 | 375 | $refreshJWT = $this->refreshJWT([ |
376 | 376 | 'payload' => $refreshPayload |
377 | 377 | ]); |
378 | 378 | |
379 | - if( isset($refreshJWT['refresh']) ) { |
|
379 | + if (isset($refreshJWT['refresh'])) { |
|
380 | 380 | return $refreshJWT['refresh']; |
381 | 381 | } |
382 | 382 | } |