@@ -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) |
@@ -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; |
@@ -117,7 +117,7 @@ |
||
| 117 | 117 | ->decode() |
| 118 | 118 | ; |
| 119 | 119 | } |
| 120 | - }else{ |
|
| 120 | + } else{ |
|
| 121 | 121 | |
| 122 | 122 | $this->header->unauthorised(); |
| 123 | 123 | } |
@@ -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 | '-', |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $directory = $customService['directory']; |
| 89 | 89 | $middleware = $customService['namespace']; |
| 90 | 90 | |
| 91 | - }else { |
|
| 91 | + } else { |
|
| 92 | 92 | $middleware = 'responsible'; |
| 93 | 93 | |
| 94 | 94 | $endpoint = str_replace( |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | if (class_exists($child)) { |
| 136 | 136 | self::$middleWareClass = new $child; |
| 137 | 137 | $this->registry[$point] = self::$middleWareClass->register(); |
| 138 | - }else{ |
|
| 138 | + } else{ |
|
| 139 | 139 | (new exception\errorException) |
| 140 | 140 | ->message("Class Error:: class {$child} needs to exist. See documentation on setting up a service.") |
| 141 | 141 | ->error('NOT_EXTENDED'); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | if( is_array($classScope) && isset($classScope[$position]) ) { |
| 216 | 216 | $endpointSettings['model']['scope'] = $classScope[$position]; |
| 217 | 217 | |
| 218 | - }else{ |
|
| 218 | + } else{ |
|
| 219 | 219 | |
| 220 | 220 | if( !is_array($classScope) ) { |
| 221 | 221 | $endpointSettings['model']['scope'] = $classScope; |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | if( is_array($classScope) && isset($classScope[$position]) ) { |
| 275 | 275 | $scope = $classScope[$position]; |
| 276 | 276 | |
| 277 | - }else{ |
|
| 277 | + } else{ |
|
| 278 | 278 | |
| 279 | 279 | if( !is_array($classScope) ) { |
| 280 | 280 | $scope = $classScope; |
@@ -76,14 +76,14 @@ discard block |
||
| 76 | 76 | /** |
| 77 | 77 | * Check if a custom directory was set in the Responsible API options |
| 78 | 78 | */ |
| 79 | - if( (isset($options['classRoute']) && !empty($options['classRoute'])) && |
|
| 79 | + if ((isset($options['classRoute']) && !empty($options['classRoute'])) && |
|
| 80 | 80 | (isset($options['classRoute']['directory']) && isset($options['classRoute']['namespace'])) |
| 81 | 81 | ) { |
| 82 | 82 | $customService = $this->options['classRoute']; |
| 83 | 83 | $directory = $customService['directory']; |
| 84 | 84 | $middleware = $customService['namespace']; |
| 85 | 85 | |
| 86 | - }else { |
|
| 86 | + } else { |
|
| 87 | 87 | $middleware = 'responsible'; |
| 88 | 88 | |
| 89 | 89 | $endpoint = str_replace( |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | if (class_exists($child)) { |
| 136 | 136 | self::$middleWareClass = new $child; |
| 137 | 137 | $this->registry[$point] = self::$middleWareClass->register(); |
| 138 | - }else{ |
|
| 138 | + } else { |
|
| 139 | 139 | (new exception\errorException) |
| 140 | 140 | ->message("Class Error:: class {$child} needs to exist. See documentation on setting up a service.") |
| 141 | 141 | ->error('NOT_EXTENDED'); |
@@ -206,16 +206,16 @@ discard block |
||
| 206 | 206 | * @var array |
| 207 | 207 | */ |
| 208 | 208 | if (array_search($endpoint, $this->registry[$api]) !== false) { |
| 209 | - if( method_exists($this->NAMESPACE_ENDPOINTS[$api], 'scope') ) { |
|
| 209 | + if (method_exists($this->NAMESPACE_ENDPOINTS[$api], 'scope')) { |
|
| 210 | 210 | $classScope = (new $this->NAMESPACE_ENDPOINTS[$api])->scope(); |
| 211 | 211 | $position = array_search($endpoint, $this->registry[$api]); |
| 212 | 212 | |
| 213 | - if( is_array($classScope) && isset($classScope[$position]) ) { |
|
| 213 | + if (is_array($classScope) && isset($classScope[$position])) { |
|
| 214 | 214 | $endpointSettings['model']['scope'] = $classScope[$position]; |
| 215 | 215 | |
| 216 | - }else{ |
|
| 216 | + } else { |
|
| 217 | 217 | |
| 218 | - if( !is_array($classScope) ) { |
|
| 218 | + if (!is_array($classScope)) { |
|
| 219 | 219 | $endpointSettings['model']['scope'] = $classScope; |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -266,16 +266,16 @@ discard block |
||
| 266 | 266 | |
| 267 | 267 | $scope = 'private'; |
| 268 | 268 | |
| 269 | - if( method_exists($this->NAMESPACE_ENDPOINTS[$api], 'scope') ) { |
|
| 269 | + if (method_exists($this->NAMESPACE_ENDPOINTS[$api], 'scope')) { |
|
| 270 | 270 | $classScope = (new $this->NAMESPACE_ENDPOINTS[$api])->scope(); |
| 271 | 271 | $position = array_search($path, $this->registry[$api]); |
| 272 | 272 | |
| 273 | - if( is_array($classScope) && isset($classScope[$position]) ) { |
|
| 273 | + if (is_array($classScope) && isset($classScope[$position])) { |
|
| 274 | 274 | $scope = $classScope[$position]; |
| 275 | 275 | |
| 276 | - }else{ |
|
| 276 | + } else { |
|
| 277 | 277 | |
| 278 | - if( !is_array($classScope) ) { |
|
| 278 | + if (!is_array($classScope)) { |
|
| 279 | 279 | $scope = $classScope; |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -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 | |
@@ -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 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | ->decode() |
| 53 | 53 | ; |
| 54 | 54 | |
| 55 | - $this->assertEquals(true, (is_array($decoded)&&!empty($decoded)) ); |
|
| 55 | + $this->assertEquals(true, (is_array($decoded) && !empty($decoded))); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * [getOptions Get the stored Responsible API options] |
| 163 | 163 | * @return array|null |
| 164 | 164 | */ |
| 165 | - public function getOptions():?array |
|
| 165 | + public function getOptions(): ?array |
|
| 166 | 166 | { |
| 167 | 167 | return $this->options; |
| 168 | 168 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | if (is_null($key) || $key == '') { |
| 219 | - if( !is_null($response) ) { |
|
| 219 | + if (!is_null($response)) { |
|
| 220 | 220 | $this->RESPONSE['response'] = $response; |
| 221 | 221 | } |
| 222 | 222 | return; |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | public function authenticate() |
| 259 | 259 | { |
| 260 | 260 | $options = $this->getOptions(); |
| 261 | - $route = (isset($options['route']) && !empty($options['route']) ) ? $options['route'] : ''; |
|
| 261 | + $route = (isset($options['route']) && !empty($options['route'])) ? $options['route'] : ''; |
|
| 262 | 262 | |
| 263 | 263 | $this->endpoints->baseApiRoot(dirname(__DIR__)); |
| 264 | 264 | $this->endpoints->register(); |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | $this->router = $router->route($route); |
| 270 | 270 | $endpoint = $this->endpoints->isEndpoint($router->getApi(), $router->getPath()); |
| 271 | 271 | |
| 272 | - if(isset($endpoint->model['scope'])) { |
|
| 272 | + if (isset($endpoint->model['scope'])) { |
|
| 273 | 273 | $_REQUEST['scope'] = $endpoint->model['scope']; |
| 274 | 274 | $this->header->setData($_REQUEST); |
| 275 | 275 | } |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | /** |
| 348 | 348 | * Check if theres a payload sent |
| 349 | 349 | */ |
| 350 | - if(isset($_REQUEST['payload'])) { |
|
| 350 | + if (isset($_REQUEST['payload'])) { |
|
| 351 | 351 | $router->setRequestBody($_REQUEST['payload']); |
| 352 | 352 | } |
| 353 | 353 | // print_r($_REQUEST); |
@@ -359,11 +359,11 @@ discard block |
||
| 359 | 359 | /** |
| 360 | 360 | * Check the access scope |
| 361 | 361 | */ |
| 362 | - if( !isset($this->router->endpoint->model['scope']) ) { |
|
| 362 | + if (!isset($this->router->endpoint->model['scope'])) { |
|
| 363 | 363 | $this->router->endpoint->model['scope'] = 'private'; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - if( isset($this->header->getMethod()->data['scope']) && |
|
| 366 | + if (isset($this->header->getMethod()->data['scope']) && |
|
| 367 | 367 | ($this->header->getMethod()->data['scope'] == 'anonymous') |
| 368 | 368 | ) { |
| 369 | 369 | $this->router->endpoint->model['scope'] = 'anonymous'; |