@@ -141,7 +141,9 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | $this->ci =& get_instance(); |
| 143 | 143 | |
| 144 | - if ($this->ci->input->is_cli_request()) return; |
|
| 144 | + if ($this->ci->input->is_cli_request()) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 145 | 147 | |
| 146 | 148 | // Load Config If Exists. |
| 147 | 149 | //$this->ci->config->load('rest', true, true); |
@@ -214,9 +216,14 @@ discard block |
||
| 214 | 216 | { |
| 215 | 217 | $auths = null; |
| 216 | 218 | $auths = $this->config['auth'] ?? null; |
| 217 | - if ($auths) $auths = is_array($auths) ? $auths : [$auths]; |
|
| 219 | + if ($auths) { |
|
| 220 | + $auths = is_array($auths) ? $auths : [$auths]; |
|
| 221 | + } |
|
| 218 | 222 | |
| 219 | - if (!$auths) return; // No authentication(s) to carry out. |
|
| 223 | + if (!$auths) { |
|
| 224 | + return; |
|
| 225 | + } |
|
| 226 | + // No authentication(s) to carry out. |
|
| 220 | 227 | |
| 221 | 228 | /** |
| 222 | 229 | * $this->process_auth() terminates the script if authentication fails |
@@ -227,7 +234,9 @@ discard block |
||
| 227 | 234 | */ |
| 228 | 235 | |
| 229 | 236 | foreach ($auths as $key => $auth) { |
| 230 | - if ($this->authPreempted) break; |
|
| 237 | + if ($this->authPreempted) { |
|
| 238 | + break; |
|
| 239 | + } |
|
| 231 | 240 | if (is_numeric($key)) { |
| 232 | 241 | $this->process_auth($auth, self::AUTH_GRAVITY); |
| 233 | 242 | } else { |
@@ -264,7 +273,9 @@ discard block |
||
| 264 | 273 | */ |
| 265 | 274 | private function auth_proceed(bool $success, int $flags):bool |
| 266 | 275 | { |
| 267 | - if ($flags & self::AUTH_GRAVITY) return $success; |
|
| 276 | + if ($flags & self::AUTH_GRAVITY) { |
|
| 277 | + return $success; |
|
| 278 | + } |
|
| 268 | 279 | if ($success) { |
| 269 | 280 | if ($flags & self::AUTH_FINAL) { |
| 270 | 281 | $this->authPreempted = true; |
@@ -298,12 +309,16 @@ discard block |
||
| 298 | 309 | $authorization = $this->get_authorization_header(); |
| 299 | 310 | $shouldProceed = $this->auth_proceed(false, $flags); |
| 300 | 311 | if ($authorization == null || substr_count($authorization, ' ') != 1) { |
| 301 | - if ($shouldProceed) return; |
|
| 312 | + if ($shouldProceed) { |
|
| 313 | + return; |
|
| 314 | + } |
|
| 302 | 315 | $this->handle_response(RESTResponse::BAD_REQUEST, $auth, 'Bad Request'); // Exits. |
| 303 | 316 | } |
| 304 | 317 | $token = explode(" ", $authorization); |
| 305 | 318 | if ($token[0] != $auth) { |
| 306 | - if ($shouldProceed) return; |
|
| 319 | + if ($shouldProceed) { |
|
| 320 | + return; |
|
| 321 | + } |
|
| 307 | 322 | $this->handle_response(RESTResponse::BAD_REQUEST, $auth, 'Bad Request'); // Exits. |
| 308 | 323 | } |
| 309 | 324 | $this->token = $token[1]; |
@@ -327,15 +342,23 @@ discard block |
||
| 327 | 342 | { |
| 328 | 343 | $username = $_SERVER['PHP_AUTH_USER'] ?? null; |
| 329 | 344 | $password = $_SERVER['PHP_AUTH_PW'] ?? null; |
| 330 | - if (!$this->auth_proceed(!$username || !$password, $flags)) $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::BASIC); // Exits. |
|
| 331 | - if (!$this->auth_proceed($this->rest_model->basicAuth($this, $username, $password), $flags)) $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::BASIC); // Exits. |
|
| 345 | + if (!$this->auth_proceed(!$username || !$password, $flags)) { |
|
| 346 | + $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::BASIC); |
|
| 347 | + } |
|
| 348 | + // Exits. |
|
| 349 | + if (!$this->auth_proceed($this->rest_model->basicAuth($this, $username, $password), $flags)) { |
|
| 350 | + $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::BASIC); |
|
| 351 | + } |
|
| 352 | + // Exits. |
|
| 332 | 353 | } |
| 333 | 354 | /** |
| 334 | 355 | * [api_key_auth description] |
| 335 | 356 | */ |
| 336 | 357 | private function api_key_auth(int $flags=self::AUTH_GRAVITY):void |
| 337 | 358 | { |
| 338 | - if (uri_string() == '') return; |
|
| 359 | + if (uri_string() == '') { |
|
| 360 | + return; |
|
| 361 | + } |
|
| 339 | 362 | $shouldProceed = $this->auth_proceed(false, $flags); |
| 340 | 363 | |
| 341 | 364 | if (!$this->ci->input->get_request_header($this->apiKeyHeader, true) && !$shouldProceed) { |
@@ -353,7 +376,9 @@ discard block |
||
| 353 | 376 | |
| 354 | 377 | $this->apiKey = $apiKey; |
| 355 | 378 | |
| 356 | - if (!$this->auth_proceed(true, $flags)) return; |
|
| 379 | + if (!$this->auth_proceed(true, $flags)) { |
|
| 380 | + return; |
|
| 381 | + } |
|
| 357 | 382 | |
| 358 | 383 | // ==== API KEY Auth Passed ==== // |
| 359 | 384 | |
@@ -414,7 +439,9 @@ discard block |
||
| 414 | 439 | // Trunctate Rate Limit Data. |
| 415 | 440 | $this->rest_model->truncateRatelimitData(); |
| 416 | 441 | // Check Whitelist. |
| 417 | - if (in_array($this->ci->input->ip_address(), $this->whitelist)) return; |
|
| 442 | + if (in_array($this->ci->input->ip_address(), $this->whitelist)) { |
|
| 443 | + return; |
|
| 444 | + } |
|
| 418 | 445 | // Should we acyually Limit? |
| 419 | 446 | if ($this->ip_per_hour > 0) { |
| 420 | 447 | $client = hash('md5', $this->ci->input->ip_address()); |
@@ -494,7 +521,9 @@ discard block |
||
| 494 | 521 | if (isset($this->config['response_callbacks'][$code])) { |
| 495 | 522 | $this->config['response_callbacks'][$code]($auth, $errorReason); |
| 496 | 523 | } |
| 497 | - if (ENVIRONMENT != 'testing') exit($code); |
|
| 524 | + if (ENVIRONMENT != 'testing') { |
|
| 525 | + exit($code); |
|
| 526 | + } |
|
| 498 | 527 | throw new Exception("Error $code in $auth", $code); |
| 499 | 528 | } |
| 500 | 529 | } |