gpt4 book ai didi

ajax - 如何将持久登录 cookie 与并行 AJAX 请求结合起来?

转载 作者:行者123 更新时间:2023-12-01 04:44:24 26 4
gpt4 key购买 nike

我已经实现了 Improved Persistent Login Cookie Best Practice对于“记住我”选项。

当请求按顺序(传统页面加载)时,这可以正常工作。在这种情况下,您可以确定下一个请求将具有相同的系列标识符和服务器上次发送的 token 。

但在 AJAX 请求的情况下,多个请求并行来自同一个浏览器,第一个请求将导致生成新的 token 号。但是其他请求不会有这个新生成的 token 号,我们会拒绝访问,将其视为盗窃。

我们如何解决这个问题?

最佳答案

基于上述 Drupal 线程 ( https://www.drupal.org/node/327263#comment-3428038 ) 上提出的解决方案,我想知道我们是否不能拥有更简单的算法。

与其将“旧”替换的 token 存储在短期缓存表中,为什么不使用当前用户 session ?

1. User logs in with PL cookie
If series & token are in PL table:
2. User session is populated with the last valid token
3. new token is given to client
4. user is logged in
If series key is in PL table, but token is not:
2. check if current user session still holds the latest replaced token
If found:
3. user is logged in. No new token is provided since one was generated in the first request.
If not found:
3. Assume keys are stolen - series is destroyed

但是,当 session 状态未正确复制到所有节点时,此算法将无法在负载平衡场景中工作!

关于ajax - 如何将持久登录 cookie 与并行 AJAX 请求结合起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13613526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com