尽管正确配置了选项和 CORS,但获取不包括 Cookie

Fetch not including Cookies despite correctly configured options and CORS

提问人:Vitor Pereira 提问时间:5/7/2023 最后编辑:Arty.SimonVitor Pereira 更新时间:5/9/2023 访问量:37

问:

我有一个后端服务器-- --和一个客户端服务器-- .我想从 发出经过身份验证的 ajax 请求。https://b.comhttps://a.coma.comb.com

在发出请求之前,用户将转到并登录。会话 cookie 将存储在带有 和 选项的浏览器中。b.comHttpOnlySecureSameSite=None

上的请求是从具有以下条件的脚本发出的fetch()a.comtype="module"

const res = await fetch("https://b.com", {
  headers: { "Accept": "application/json" },
  credentials: "include",
});

后端返回具有相应 CORS 标头的响应。即

access-control-allow-credentials: true
access-control-allow-methods: GET
access-control-allow-origin: https://a.com

尽管如此,会话 cookie 未包含在请求中,因此身份验证不起作用。fetch()

我错过了什么?

Ruby-on-Rails AJAX CORS 跨域 fetch-api

评论


答:

0赞 Vitor Pereira 5/7/2023 #1

一切都在正确完成。事实证明,Chrome 阻止了所有第三方 Cookie。