简体   繁体   English

Symfony4 REST API (LexikJWTAuthenticationBundle) 的并发请求

[英]Concurrent requests for Symfony4 REST API (LexikJWTAuthenticationBundle)

I'm a bit lost right now and could use a push in the right direction.我现在有点迷路,可以朝正确的方向推动。

In short简而言之

  • PHP Symfony 4 project (mostly default configuration), hosted on Google Cloud App Engine PHP Symfony 4 项目(大部分是默认配置),托管在 Google Cloud App Engine 上
  • REST API, authentication via LexikJWTAuthenticationBundle REST API,通过LexikJWTAuthenticationBundle进行身份验证
  • Requests need to pass auth token on every request (Symfony firewall is stateless: true )请求需要在每个请求上传递身份验证令牌(Symfony 防火墙是stateless: true
  • Single Page Application as API consumer (React frontend)单页应用程序作为 API 消费者(React 前端)

In my use-case, one authenticated user opens page X .在我的用例中,一个经过身份验证的用户打开页面X On this page, there are three different sections with data, that need to be loaded from the backend.在此页面上,需要从后端加载三个不同的数据部分。 Therefore, I have three API endpoints to be fetched.因此,我要获取三个 API 端点。

When opening the page, these three requests aren't performed simultaniously, they wait for each other.打开页面时,这三个请求不是同时执行的,而是相互等待的。 In this SO question there's already mentioned, that Symfony doesn't support concurrent requests for one user session or one could manually close an open session.这个SO question 中已经提到,Symfony 不支持对一个用户 session 的并发请求,或者可以手动关闭打开的 session。 Since I'm not using sessions at all I don't want to mess with closing random stuff.因为我根本不使用会话,所以我不想搞乱关闭随机的东西。

But my question: I believe having a stateless API, where the user isn't stored in a server session.但我的问题是:我相信有一个无状态的 API,其中用户没有存储在服务器 session 中。 I have to pass the JWT token on every request.我必须在每个请求上传递 JWT 令牌。

-> Should it be possible having the three authenticated requests being served in parallel with a stateless REST API - or isn't it just not possible as soon as 'a user is involved'? -> 是否有可能让三个经过身份验证的请求与无状态的 REST API 并行服务 - 或者一旦“涉及用户”就不可能了吗?

fyi: Trying three requests for an un-authed endpoints shows me parallel requests.仅供参考:尝试对未经身份验证的端点的三个请求向我显示并行请求。

Code fragments代码片段

security.yaml安全性.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 }

Okay, nevermind, it was a configuration problem with my Staging environment.好吧,没关系,这是我的暂存环境的配置问题。 For the API endpoint I tested, a session was created.对于我测试的 API 端点,创建了 session。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM