【问题标题】:Basic HTTP Authentication not working in Google App Engine基本 HTTP 身份验证在 Google App Engine 中不起作用
【发布时间】:2017-06-07 21:57:42
【问题描述】:

我正在为我的移动应用构建一个后端系统。我想用基本的 HTTP Auth 保护内容。

我已经编写了以下代码,它在 localhost 上运行起来就像轻而易举。

if ($_SERVER['PHP_AUTH_USER'] != 'admin@denda.in' && $_SERVER['PHP_AUTH_PW'] != '11test11') {
    header('WWW-Authenticate: Basic realm="Denda Backend"');
    header('HTTP/1.0 401 Unauthorized');
    echo "Wrong credentials :-(";
    exit;
}

但是当我将应用程序上传到 GAE 时,这不起作用。我不断收到相同的对话框。在网上也找不到任何可靠的帮助。

谢谢, 克里什

【问题讨论】:

    标签: php google-app-engine


    【解决方案1】:

    我知道这是一个老问题,但很高兴知道它

    if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
        $nobasic = substr($_SERVER['HTTP_AUTHORIZATION'],6);            // removing 'Basic ' from the string
        $decoded = base64_decode($nobasic);                                   // decoding string with user:password
        list($client_user, $client_pass) = explode(':',$decoded);
        if ($client_user == "user" && $client_pass == "password") {
            // Successfully authenticated
        } else {
            // Authentication failed, username or password are wrong
            header('WWW-Authenticate: Basic realm="site"');
            header('HTTP/1.0 401 Unauthorized');
            echo "Wrong credentials :-(";
            exit;
        }
    } else {
        // Not authenticated as there is no appropriate header in HTTP request
        header('WWW-Authenticate: Basic realm="site"');
        header('HTTP/1.0 401 Unauthorized');
        echo "Wrong credentials :-(";
        exit;
    }
    

    【讨论】:

    • 在 2020 年,我发现应用引擎似乎没有传递正确的标题:/
    猜你喜欢
    • 2020-01-26
    • 1970-01-01
    • 2014-01-22
    • 2014-12-31
    • 2013-03-23
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    相关资源
    最近更新 更多