在其他子域中设置会话 cookie 的问题

Issues setting session cookies in other subdomain

我已经在 HTTP set-cookie 主题上翻来覆去一段时间了,但我没有取得任何进展。我的情况如下:

我的 API 托管在 api.mysite.com 上,我在 admin.mysite.com 上有一个管理仪表板。我从 admin.mysite.com 向 api.mysite.com/login 发出 POST 请求以验证凭据,它 returns 会话 cookie。 cookie配置为:


session_set_cookie_params([
    'lifetime' => 36000,
    'path' => '/',
    'domain' => '.mysite.com.co',
    'secure' => 1,
    'httponly' => 0,
    'samesite' => 'None'
]);

响应似乎还不错:

HTTP/1.1 200 OK
Date: Thu, 04 Nov 2021 16:22:57 GMT
Server: Apache/2.4.41 (Ubuntu)
Strict-Transport-Security: max-age=63072000
Access-Control-Allow-Origin: https://admin.mysite.com
Access-Control-Allow-Headers: x-requested-with, Content-Type, origin, accept, authorization, client-security-token, Cache-Control, X-Mashape-Authorization
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Expose-Headers: Content-Security-Policy, Location
Access-Control-Max-Age: 1000
Upgrade: h2
Connection: Upgrade, Keep-Alive
Set-Cookie: PHPSESSID=hash; expires=Fri, 05-Nov-2021 02:22:57 GMT; Max-Age=36000; path=/; domain=.mysite.com; secure; SameSite=None
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Access-Control-Allow-Credentials: true
Content-Length: 549
Keep-Alive: timeout=5, max=100
Content-Type: text/html; charset=UTF-8

但是没有存储cookie。但是,如果我从 api.mysite.com/testCookies 向 api.mysite.com/login 发出请求,它就会被存储,所以它似乎是一个 domain/site 问题(也许是 CORS? )

我将不胜感激有关此主题的任何指导。

here 相同的答案。重点是withCredentials属性的用法。虽然不确定,为什么我必须发送它们,即使 cookie 源自子域 A 并设置在子域 B 上。