-1

I create two auth "admin" and "user" in Symfony 5 ( security section )

I set them in main firewall.

Now how can I define "remember me" for each one separately??

For admin:

remember_me:
    secret: '%kernel.secret%'
    lifetime: 86400

For users:

remember_me:
    secret: '%kernel.secret%'
    lifetime: 32598000

And my security.yaml is:

security:
    encoders:
        App\Entity\Admin:
            algorithm: auto
        App\Entity\User:
            algorithm: auto
    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_admin_provider:
            entity:
                class: App\Entity\Admin
                property: username
        app_user_provider:
            entity:
                class: App\Entity\User
                property: username
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: true
            lazy: true
            provider: app_user_provider
            guard:
                authenticators:
                    - App\Security\AdminAuthenticator
                    - App\Security\UserAuthenticator
                entry_point: App\Security\UserAuthenticator
            logout:
                path: app_logout
                # where to redirect after logout
                # target: app_any_route
            # activate different ways to authenticate
            # https://symfony.com/doc/current/security.html#firewalls-authentication
            # https://symfony.com/doc/current/security/impersonating_user.html
            # switch_user: true
    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    access_control:
        # - { path: ^/admin, roles: ROLE_ADMIN }
        # - { path: ^/profile, roles: ROLE_USER }
BTS
  • 1

1 Answers1

0

You can divide your main firewall to two and setup remember_me parameter as you want for each role. You can read more about firewalls from here: https://symfony.com/doc/current/security.html#firewalls-authentication

k1000
  • 78
  • 1
  • 5