2015-08-09 147 views
0

我正在使用CakePHP作爲單頁面應用程序的REST API。CakePHP 3刪除WWW身份驗證

在繼續之前,每個請求都經過認證和授權。

問題是,在登錄時,如果憑據錯誤,Cake返回401,瀏覽器在彈出窗口中顯示自己的服務器日誌。

我相信有一種方法可以通過取消設置WWW-authenticate header來阻止它,但我需要知道如何。有人可以解釋如何取消設置該標題嗎?

+0

您將需要提供一些更多的信息,比如你的身份驗證設置代碼。 – user221931

回答

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' 
    ] 
]); 

參見