使用多个防火墙和多个防护

问题描述

我有一个Symfony 5.1(全栈)应用程序,并且我正在使用Api平台。现在,我想使用API​​令牌访问API(使用Custom Authentication System with Guard),但是已经登录的用户应该能够在没有令牌的情况下访问API。

我使用了Symfony文档中有关Multiple Guard Authenticators的示例,并添加了第二个身份验证器:

$container->loadFromExtension('security',[
    // ...
    'firewalls' => [
        'api' => [
            'context' => 'my_context','pattern' => '^/api','guard' => [
                'entry_point' => LoginFormAuthenticator::class,'authenticators' => [
                    LoginFormAuthenticator::class,ApiTokenAuthenticator::class,],'default' => [
            'context' => 'my_context','anonymous' => true,'lazy' => true,'guard' => [
                'authenticators' => [
                    LoginFormAuthenticator::class,);

当我将TokenAuthenticator用作entry_point时,登录用户无法访问对^/api/的请求。他们会得到一个401 Unauthorized(“在TokenStorage中找不到令牌。”)。

当我将ApiTokenAuthenticator用作entry_point时,对^/api/的(XMLHttp-)请求被重定向到/login而不是401 Unauthorized

我如何拥有两个验证者都可以访问的API端点?

编辑:感谢Cerad,我将context添加到两个防火墙中,如here所述。没什么区别。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...