2

自定义身份验证对象中的身份验证方法永远不会被调用。这是一个错误还是我错过了什么?

我没有在日志中得到任何东西,我只是被重定向到用户/登录名(或我指定的那个)

蛋糕版本:2.4.1

<?php
//My custom Auth Class
//Path: app/Controller/Component/Auth/HashAuthenticate.php
App::uses('BaseAuthenticate', 'Controller/Component/Auth');

class HashAuthenticate extends BaseAuthenticate
{
    public function authenticate(CakeRequest $request, CakeResponse $response)
    {
        //Seems to not be called
        CakeLog::write('authenticate');
        debug($this);
        die('gaah');
    }
}

如果我添加方法 getUser() (或 unauthenticated() ),那些会被调用,所以至少我知道 cake 找到了类等等。它只是跳过验证方法。

AppController 看起来像这样

<?php
// AppController
App::uses('Controller', 'Controller');
App::uses('HashAuthenticate', 'Controller/Component/Auth'); 

class AppController extends Controller {

    public $helpers = array('Html', 'Form', 'Session');
    public $components =    array('Auth' => array(
        'authenticate' => array('Hash'),
        'authorize'      => array('Controller'),
        )
    );
}

我在这里发现了一个类似的问题:CakePHP 2.x custom "Authentication adapter "LdapAuthorize" is not found but there's the issue is typos.

4

1 回答 1

1

我错误地认为,每当未经身份验证的用户尝试访问受 Auth 保护的内容时,都会调用身份验证。

正如 ndm 指出的那样,仅在执行时才调用身份验证$this->Auth->login()

我在这里尝试完成的事情是让用户通过链接登录,但不是以无状态方式登录。他们不应该每次都提供相同的哈希(在我的情况下),只需一次。相反,我将在每次用户尝试访问受保护的内容时调用的 getUser() 方法中设置状态(会话)。

所以希望这可以帮助其他有同样问题的人。

于 2013-11-07T17:30:29.803 回答