【问题标题】:cakephp: Custom Authentication Object authenticate not calledcakephp:自定义身份验证对象身份验证未调用
【发布时间】:2013-11-19 08:41:03
【问题描述】:

从不调用自定义身份验证对象中的身份验证方法。这是故障还是我遗漏了什么?

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

蛋糕版本: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 &quot;LdapAuthorize&quot; was not found 但问题是错别字。

【问题讨论】:

  • 能否请您也显示您的控制器登录操作?很像这就是问题所在。
  • 你是最正确的先生。我错误地认为,每当未登录的用户尝试访问需要身份验证的内容时,都会调用身份验证。但是正如您所说,调用身份验证的是$this-&gt;Auth-&gt;login()。我将专注于getUser()

标签: cakephp authentication cakephp-2.4


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2020-04-01
    • 2022-12-10
    • 2013-11-10
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    相关资源
    最近更新 更多