From 21b9feb0ef092afffc3afadc6e3a22366ab2e055 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 21 Jan 2025 05:14:18 -0800 Subject: [PATCH] Refactor auth method: http basic > user login --- includes/authenticate.php | 10 ++-------- src/RaspAP/Auth/HTTPAuth.php | 18 ++++-------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/includes/authenticate.php b/includes/authenticate.php index bceac97d..401ab443 100755 --- a/includes/authenticate.php +++ b/includes/authenticate.php @@ -1,16 +1,10 @@ isLogged()) { - if ($auth->login($user, $pass)) { - $config = $auth->getAuthConfig(); - } else { - $auth->authenticate(); - } + $auth->authenticate(); } } + diff --git a/src/RaspAP/Auth/HTTPAuth.php b/src/RaspAP/Auth/HTTPAuth.php index 9751075f..d32a36ad 100755 --- a/src/RaspAP/Auth/HTTPAuth.php +++ b/src/RaspAP/Auth/HTTPAuth.php @@ -15,12 +15,6 @@ namespace RaspAP\Auth; class HTTPAuth { - - /** - * @var string $realm - */ - public $realm = 'Authentication Required'; - /** * Stored login credentials * @var array $auth_config @@ -57,15 +51,11 @@ class HTTPAuth public function authenticate() { if (!$this->isLogged()) { - header('HTTP/1.0 401 Unauthorized'); - header('WWW-Authenticate: Basic realm="'.$this->realm.'"'); - if (function_exists('http_response_code')) { - // http_response_code will respond with proper HTTP version - http_response_code(401); - } else { - header('HTTP/1.0 401 Unauthorized'); + $redirectUrl = $_SERVER['REQUEST_URI']; + if (strpos($redirectUrl, '/login') === false) { + header('Location: /login?action=' . urlencode($redirectUrl)); + exit(); } - exit('Not authorized'.PHP_EOL); } }