【问题标题】:Use a cookie on subdomains defined from a sub subdomain在从子子域定义的子域上使用 cookie
【发布时间】:2021-10-22 10:34:08
【问题描述】:

我正在尝试创建一个身份验证页面,该页面将通过 cookie 返回可在不同子域上使用的 JWT。这是我尝试实现的场景:

  1. 用户转到authenticate.staging.example.com
  2. 该页面将向admin.api.staging.example.com 发出 HTTP 请求(withCredentials: true)并返回这些标头:
Set-Cookie: jwt=myToken; Domain=.staging.example.com; SameSite=None; Secure
Access-Control-Allow-Headers: 'Accept, Content-Type'
Access-Control-Allow-Origin: 'https://authenticate.staging.example.com'
Access-Control-Allow-Methods: 'GET,POST,PATCH,PUT,DELETE,OPTIONS'
Access-Control-Allow-Credentials: 'true'
  1. 当用户转到admin.staging.example.comdocs.staging.example.com时,会为所有请求(index.html等)发送JWT cookie

目前,我收到了 cookie,但当我转到 admin.staging.example.comdocs.staging.example.com 时它没有发送。如果该解决方案仅适用于最新的 Chrome,则没有问题。

感谢您的帮助

【问题讨论】:

    标签: google-chrome cookies cross-domain subdomain session-cookies


    【解决方案1】:

    我通过在我的 cookie 中添加 Path=/HttpOnly 使其工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-03
      • 2013-09-21
      • 2018-03-09
      • 1970-01-01
      • 2015-07-04
      • 2018-10-07
      • 2011-04-10
      • 2011-01-11
      相关资源
      最近更新 更多