如何分别为每一个定义“记住我”? Symfony 5
Posted
技术标签:
【中文标题】如何分别为每一个定义“记住我”? Symfony 5【英文标题】:how can I define "remember me" for each one separately? Symfony 5 【发布时间】:2021-08-12 17:41:23 【问题描述】:我在 Symfony 5 中创建了两个身份验证“admin”和“user”(安全部分)
我将它们设置在main
防火墙中。
现在如何分别为每个人定义“记住我”??
对于管理员:
remember_me:
secret: '%kernel.secret%'
lifetime: 86400
对于用户:
remember_me:
secret: '%kernel.secret%'
lifetime: 32598000
我的 security.yaml 是:
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
【问题讨论】:
【参考方案1】:您可以将主防火墙一分为二,并根据需要为每个角色设置 remember_me 参数。你可以从这里阅读更多关于防火墙的信息:https://symfony.com/doc/current/security.html#firewalls-authentication
【讨论】:
以上是关于如何分别为每一个定义“记住我”? Symfony 5的主要内容,如果未能解决你的问题,请参考以下文章