【问题标题】:CakePHP 3 remove WWW-authenticateCakePHP 3 删除 WWW-authenticate
【发布时间】:2015-08-09 13:09:44
【问题描述】:

我将 CakePHP 用作单页应用程序的 REST API。

每个请求在继续之前都经过身份验证和授权。

问题是,在登录时,如果凭据错误,Cake 会返回 401,并且浏览器会在弹出窗口中显示自己的服务器日志。

我相信有办法通过取消设置 WWW-authenticate header 来阻止它,但我需要知道如何。有人可以解释如何取消设置该标题吗?

【问题讨论】:

  • 您需要提供更多信息,例如您的身份验证设置代码。

标签: php cakephp authentication cakephp-3.0


【解决方案1】:

标头正在\Cake\Auth\BasicAuthenticate 身份验证适配器中设置。

https://github.com/cakephp/cakephp/blob/3.0.11/src/Auth/BasicAuthenticate.php#L85-L110

它是硬编码的,所以如果你想改变这个行为,你必须创建一个自定义/扩展的身份验证适配器并覆盖这个行为。

这是一个简单的例子:

src/Auth/MyCustomBasicAuthenticate.php

namespace App\Auth;

use Cake\Auth\BasicAuthenticate;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\Network\Response;

class MyCustomBasicAuthenticate extends BasicAuthenticate
{
    public function unauthenticated(Request $request, Response $response)
    {
        throw new UnauthorizedException();
    }
}

控制器

$this->loadComponent('Auth', [
    'authenticate' => [
        'MyCustomBasic'
    ]
]);

另见

【讨论】:

    猜你喜欢
    • 2018-10-19
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    相关资源
    最近更新 更多