无法在Symfony4中注销用户 [英] Can't Logout user in Symfony4

查看:108
本文介绍了无法在Symfony4中注销用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将使用Symfony2.7构建的项目更新为Symfony4,一切正常,并具有良好的兼容性,但是应该没问题的是,内置资源安全层无法按预期工作

I'm updating a project built with Symfony2.7 to Symfony4, everything is working fine and have good compatibility, but one thing that should be fine, a built-in resource, the security layer, doesn't work as expected.

我面临的问题是我无法再注销用户.我遵循了指南上的步骤,但没有任何更改.

The problem I'm facing is that I can't logout users anymore. I followed the steps on the guide but nothing changed.

下面是安全性配置:

#config/packages/security.yaml
security:
    encoders:
        App\Entity\Clients:
            algorithm: bcrypt

    providers:
        app_user_provider:
            entity:
                class: App\Entity\Clients
    firewalls:    
        app:
            pattern: ^/
            anonymous: ~
            provider: app_user_provider
            remember_me:
                secret: "%kernel.secret%"
            form_login:
                use_referer: true
                login_path: login
                check_path: login_check
                always_use_default_target_path: false
                default_target_path: dashboard
                csrf_token_generator: security.csrf.token_manager
            logout:
                path: logout
                target: home
                invalidate_session: false

我使用的路径是路由名称,但也尝试了路径本身.

The paths I'm using are route names, but also tried the path itself.

我通常可以登录任何用户,但是当我单击注销路由时,我只是重定向到了本地路由,但是该用户仍通过了身份验证.

I can normally login any user, but when I hit the logout route, I'm just redirected to home route, but the user is still authenticated.

试图设置自定义处理程序注销,例如:

Tried to set a custom handler logout like:

logout:
    handlers: [logout_handler]

它引用了实现 Symfony \ Component \ Security \ Http \ Logout \ LogoutHandlerInterface 的服务,但它甚至没有调用处理程序.

It references to a service implementing Symfony\Component\Security\Http\Logout\LogoutHandlerInterface, but it didn't even call the handler.

如果我只能使用默认处理程序,那就太好了,并且有必要保持"remember_me"行为,该行为在2.7中也可以正常工作.

It would be great if I could only use the default handler, and it's necessary to maintain the "remember_me" behavior, which was also working fine in 2.7.

有人可以帮我吗?

我的配置route.yaml为空,因为我使用的是注释路由,因此config/packages/routing.yaml如下:

My config routes.yaml is empty, 'cause I'm using annotation routes, the config/packages/routing.yaml is as follows:

framework:
    router:
        strict_requirements: ~

就像使用 composer create-project 命令初始化时一样. 对于注释配置,我有文件config/routes/annotations.yaml:

Just like when initialized with the composer create-project command. And for the annotations config I have the file config/routes/annotations.yaml:

controllers:
    resource: ../../src/Controller/
    type: annotation

同样,它是自己创建的配方的配置.

Again, it's the config the recipe created by itself.

推荐答案

我通过使用** LogoutSuccessHandler *(

I achieved the result of logging out by removing the REMEMBERME cookie with a **LogoutSuccessHandler* (reference).

我认为这是一个丑陋的解决方法,但是结果令人满意,因为一切正常.但是仍然不知道为什么它不能自动与配置一起使用,也为什么我不能使用自定义注销处理程序.如果有人提出更好的答案,我可以将其标记为可接受的答案.

I think of this as being an ugly workaround, but the result was satisfactory, as everything worked fine. But still don't know why it didn't worked automatically with the configs, also why I couldn't use a custom logout handler. If anyone comes up with better answer, I can mark it as the accepted answer.

这篇关于无法在Symfony4中注销用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆