首页 > 解决方案 > 如何将 CakeDc\Auth 与未经验证的允许操作一起使用?

问题描述

对于 CakePHP 4.0 和CakeDc\Auth 6.0,我尝试使用中间件实现(而不是组件)设置基于 RBAC 的权限应用程序。

一切正常,除了无需身份验证即可访问的操作(如/login/logout/recover)。

Authentication docs之后,我在我的 中包含了该操作UsersController::beforeFilter,但我得到了异常:ROOT/vendor/cakephp/authorization/src/Middleware/RequestAuthorizationMiddleware.php

$identity = $request->getAttribute($this->getConfig('identityAttribute'));

$result = $service->canResult($identity, $this->getConfig('method'), $request);
    if (!$result->getStatus()) {
        throw new ForbiddenException($result);          <---- That line
    }

    return $handler->handle($request);
}

我的Application.php基本设置在这里:https ://gist.github.com/CauanCabral/27bdb295f7854116e875e4b0c44712​​89

我错过了什么?

标签: phpauthenticationcakephpauthorizationcakedc

解决方案


推荐阅读