X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSecurity%2FBasicAuth.php;h=7b6a6b082502d982e0827141434a7c31df437b84;hb=ecaed2a8450ab8423b4e5ef60ac9a249be60901a;hp=2b4baaa36ed65f9be86c5ac46b80caaea9e145d4;hpb=abbe7895ae48570a9fc87b4ed85fd8a75c1c83f5;p=friendica.git diff --git a/src/Security/BasicAuth.php b/src/Security/BasicAuth.php index 2b4baaa36e..7b6a6b0825 100644 --- a/src/Security/BasicAuth.php +++ b/src/Security/BasicAuth.php @@ -62,7 +62,7 @@ class BasicAuth return (int)self::$current_user_id; } - public static function setCurrentUserID(int $uid) + public static function setCurrentUserID(int $uid = null) { self::$current_user_id = $uid; } @@ -78,9 +78,9 @@ class BasicAuth return []; } - if (!empty(self::$current_token)) { - return self::$current_token; - } + //if (!empty(self::$current_token)) { + // return self::$current_token; + //} $source = $_REQUEST['source'] ?? ''; @@ -123,7 +123,6 @@ class BasicAuth private static function getUserIdByAuth(bool $do_login = true):int { $a = DI::app(); - Session::set('allow_api', false); self::$current_user_id = 0; // workaround for HTTP-auth in CGI mode @@ -178,7 +177,10 @@ class BasicAuth return 0; } Logger::debug('Access denied', ['parameters' => $_SERVER]); - header('WWW-Authenticate: Basic realm="Friendica"'); + // Checking for commandline for the tests, we have to avoid to send a header + if (php_sapi_name() !== 'cli') { + header('WWW-Authenticate: Basic realm="Friendica"'); + } throw new UnauthorizedException("This API requires login"); } @@ -187,15 +189,10 @@ class BasicAuth DI::auth()->setForUser($a, $record, false, false, $login_refresh); - Session::set('allow_api', true); - Hook::callAll('logged_in', $record); - if (Session::get('allow_api')) { - self::$current_user_id = local_user(); - } else { - self::$current_user_id = 0; - } + self::$current_user_id = local_user(); + return self::$current_user_id; } }