我想創建一個摘要身份驗證使用CakePHP 3.1下的身份驗證組件,我遇到了問題。我使用下面的代碼,並且在上一個彈出窗口輸入正確的用戶名和密碼後,彈出了HTTP-Authentication彈出窗口。然後,如果我按取消我有這個:Cake \ Auth \ BasicAuthenticate->未認證。摘要鑑別下CakePHP 3
有人能告訴我我做錯了什麼嗎?
AppController.php
$this->loadComponent('Auth', [
'authorize' => 'Controller',
'loginRedirect' => [
'controller' => 'Users',
'action' => 'index'
],
'authenticate' => [
'Digest' => [
'fields' => ['username' => 'username', 'password' => 'digest_hash'],
'userModel' => 'Users',
],
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login',
],
'storage' => 'Memory',
'unauthorizedRedirect' => false
]);
UserTable.php
public function beforeSave(Event $event)
{
$entity = $event->data['entity'];
// Make a password for digest auth.
$entity->digest_hash = DigestAuthenticate::password(
$entity->username,
$entity->plain_password,
env('SCRIPT_NAME')
);
return true;
}
在客戶端部分
public function digest(){
$http = new Client();
$response = $http->get('http://localhost/project/api/v1/users/view/22', [], [
'auth' => [
'type' => 'digest',
'username' => 'Digest',
'password' => 'my_password',
]
]);
當我在調試-kit的環境檢查,我有這樣的:
PHP_AUTH_DIGEST username="Digest", realm="localhost", nonce="57ac3609a5b79", uri="/project/api/v1/users/view/22", response="af0e1fe455aa7f1475df715ef5231b56", opaque="421aa90e079fa326b6494f812ad13e79", qop=auth, nc=00000001, cnonce="0bb461453700ebc1"