CakePHP 3删除WWW-authenticate

时间:2015-08-09 13:09:44

标签: php cakephp authentication cakephp-3.0

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

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

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

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

1 个答案:

答案 0 :(得分:1)

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

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

它是硬编码的,因此如果您想要更改此行为,则必须创建自定义/扩展身份验证适配器并覆盖此行为。

这是一个简单的例子:

<强>的src /认证/ 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'
    ]
]);

另见

相关问题