首页 > 解决方案 > 无法使用多个提供商和防火墙注销 Symfony 5

问题描述

我必须处理 2 种类型的身份验证(对于管理员部分和客户部分)我确实成功地使用 2 个单独的提供者和 2 个单独的身份验证页面制作了 2 个单独的身份验证器,2 个表单连接正常工作。但我面临一个关于注销操作的问题。

这是security.yaml示例:

firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        customer:
            pattern: ^/profile|/login
            entry_point: App\Security\CustomerAuthenticator
            provider: app_customer_provider
            custom_authenticator: App\Security\CustomerAuthenticator
            logout:
                path: app_logout
                target: /
                invalidate_session: true
        administrator:
            pattern: ^/admin|/accessadmin
            entry_point: App\Security\AdminAuthenticator
            lazy: true
            provider: app_admin_provider
            custom_authenticator: App\Security\AdminAuthenticator
            logout:
                path: app_logout
                target: /
                invalidate_session: true

这是 SecurityController.php 中的注销功能

/**
     * @Route("/logout", name="app_logout")
     */
    public function logout()
    {
        throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
    }

当我尝试访问 /logout URL 时,我实际上抛出了异常(好吧,你会说它是这样编码的)。问题是,如果通过“主要”属性重命名防火墙之一,在这种情况下,注销功能可以完美运行。

我不知道此时我缺少什么...如果无论如何调用注销功能,是否有解决方案可以使用我将放入公共功能的任何功能强制注销logout()

标签: symfony

解决方案


推荐阅读