0
votes

I'm using Symfony 3.1 with FOSUserBundle.

I read the docs and integrated FOS in Symfony, here all right, the registration seems to work well and persists the data to the DB, BUT, if I try to login I get redirected again to the login page as an anonymous user.

I checked the Symfony Profiler, and I can see that when it's called the path /login_check (in the profiler) the user result as authenticated, but then after the /login_check phase, when I get redirected, the user is as anonymous...

--

/login_check from profiler:

Property Value

Roles [ROLE_USER]

Inherited Roles none

Token class Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken

--

The sessions seems to exist (dump(app.session)) is not empty, but no stores data of user.

That'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:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            login_path: /login
            check_path: /login_check
            default_target_path: /redirLogIn
#                csrf_token_generator: security.csrf.token_manager

        logout:       true
        anonymous:    true

access_control:
    - { 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 disabled the csrf token due to problems on registration)

(This is an intranet, there is no "homepage", as you open the site you are requested to login)

Why this?

Thanks

2
Have you resolved this issue? I'm also facing the same issue, /login_check redirecting to /login page - Allahbakash.G

2 Answers

0
votes

I'm not sure I understand the question you are asking, but maybe it's why you are being directed to login when you open the site?

If so, this is why:

default_target_path: /redirLogIn

Change the above to the path (route) you need.

0
votes

You need to improve the indentation in the file

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

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN
    # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
    providers:
        in_memory:
            memory: ~
        fos_userbundle:
            id: fos_user.user_provider.username_email
    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            # activate different ways to authenticate

            # http_basic: ~
            # http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

            # form_login: ~
            # http://symfony.com/doc/current/cookbook/security/form_login_setup.html
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
                # if you are using Symfony < 2.8, use the following config instead:
                # csrf_provider: form.csrf_provider

            logout:       true
            anonymous:    true

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