symfony - 为什么 Symfony Guard 对每个请求都会触发 'security.interactive_login' 事件?

标签 symfony symfony-3.2

我有一个 Symfony 3.2 应用程序,它公开 REST API 并使用 Json Web token (JWT) 进行身份验证。我最近改用 Symfony 的 Guard 组件。现在我的 security.yml 包含防火墙配置部分,如下所示(我使用的是 Lexik JWT 包 2.4.0,但这应该不重要):

firewalls:
    # ...
    api:
        pattern:   ^/api
        stateless: true
        guard:
            authenticators:
               - lexik_jwt_authentication.jwt_token_authenticator

自从我进行此切换后,我注意到每个请求都像用户刚刚登录一样进行处理,即触发security.interactive_login事件。 在文档( http://symfony.com/doc/current/components/security/authentication.html#authentication-events )中指出:

The security.interactive_login event is triggered after a user has actively logged into your website. It is important to distinguish this action from non-interactive authentication methods, such as: authentication based on a "remember me" cookie, authentication based on your session, authentication using a HTTP basic or HTTP digest header. You could listen on the security.interactive_login event, for example, in order to give your user a welcome flash message every time they log in.

因此,我绝对不希望每个请求都会发生此事件 - 我宁愿期望每个请求都获得 security.authentication.success 事件,如文档中所指出的。

但是,Symfony 的 GuardAuthenticatorHandler 类在其 authenticateWithToken 方法中调度 security.interactive_login 事件,并且该方法由 每个请求上的 GuardAuthenticationListener。 这是 Symfony 中的错误、我这边的误解还是由于配置不正确造成的?

(这不是一个哲学问题 - 就我而言,它导致了一个具体问题,即用户的上次登录时间会根据每个请求进行更新,这是没有意义的。)

最佳答案

你应该改变这个

        stateless: false

关于symfony - 为什么 Symfony Guard 对每个请求都会触发 'security.interactive_login' 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44162303/

相关文章:

symfony - 如何给电子邮件发件人命名?

php - 使用事件语言在 Twig 中组合变量

symfony - 使用 Assetic 通过参数化 url 清除 Assets 缓存

php - 使用 Doctrine 按类别提取产品列表

php - Symfony3 无法使用服务中的路由器创建已翻译的路由

symfony - 选中表单类型复选框以创建表单 SonataAdminBundle

php - 存储其中包含 unicode 字符的字符串

symfony - Guzzle 安装

php - 选择时找不到 Symfony3 Doctrine 多对多列

javascript - 谷歌地图不显示