【发布时间】:2021-06-25 13:05:21
【问题描述】:
我现在有点迷茫,可以朝正确的方向推动。
总之
- PHP Symfony 4 项目(大部分是默认配置),托管在 Google Cloud App Engine 上
- REST API,通过LexikJWTAuthenticationBundle 进行身份验证
- 请求需要在每个请求上传递身份验证令牌(Symfony 防火墙是
stateless: true) - 作为 API 使用者的单页应用程序(React 前端)
在我的用例中,一位经过身份验证的用户打开页面X。在此页面上,需要从后端加载三个不同的数据部分。因此,我要获取三个 API 端点。
在打开页面时,这三个请求不是同时执行的,它们相互等待。在this SO 问题中已经提到,Symfony 不支持一个用户会话的并发请求,或者一个可以手动关闭打开的会话。 因为我根本不使用会话,所以我不想乱关闭随机的东西。
但是我的问题: 我相信有一个无状态的 API,用户不存储在服务器会话中。我必须在每个请求上传递 JWT 令牌。
-> 是否有可能让三个经过身份验证的 请求与无状态 REST API 并行提供 - 还是说一旦“涉及用户”就不可能?
fyi:尝试三个未验证端点的请求会显示并行请求。
代码片段
security.yaml
firewalls:
login:
pattern: ^/api/v1/login
stateless: true
anonymous: true
json_login:
check_path: /api/v1/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
pattern: ^/api/v1
stateless: true
access_denied_handler: App\Security\AccessDeniedHandler
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/api/v1/, role: IS_AUTHENTICATED_FULLY }
【问题讨论】:
标签: php symfony4 restful-authentication lexikjwtauthbundle