elec
elec

Reputation: 51

FOSUserBundle - You must activate the logout in your security firewall configuration

I am using Symfony 2.8.2 with FOSUserBundle. When I'm trying to logout, I got the following error:

You must activate the logout in your security firewall configuration

Here's my security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/login
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
            anonymous: true
            logout:
                path: /logout
                target: /login

    access_control:
        - { path: ^/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }
        - { path: ^/, role: ROLE_USER }

I've also tried to set logout: true but nothing changed.

P.S. I'm not using Sonata, just FOSUserBundle.

What's the reason I'm getting this error?

Upvotes: 5

Views: 6039

Answers (2)

Meriem Bader
Meriem Bader

Reputation: 173

you must add in your security.yml

firewalls:
       secured_area:   
              logout:
                  path:   /logout
                  target: /

and in your routing.yml

logout:
    path: /logout

Upvotes: 1

martin
martin

Reputation: 96959

It seems like you have wrong pattern for main firewall.

Setting pattern: ^/login makes this firewall valid only for matching URLs which is only /login URL.

Also, logout URL has to be inside firewall's secured area.

Upvotes: 2

Related Questions