cookies - httponly cookie 未设置
问题描述
有这个设置:
localhost:9990
身份验证服务器(密钥斗篷):,- 后端:
localhost:8080
, - 前端(SPA):
localhost:3000
用户可以通过将用户名 + 密码发送到以下地址“登录”/获取 SPA 上的令牌:
http://localhost:9990/auth/realms/w/protocol/openid-connect/token
然后我在 auth-server 上调用另一个 url,它应该设置 keycloak 需要 SSO/remember-me 的 cookie(它应该设置一些HttpOnly
cookie):
.then(t => keycloakInstance.init({
token: t.access_token,
refreshToken: t.refresh_token,
checkLoginIframe: false, // required to init with token
})
.then((authenticated) => {
console.log('auth', authenticated); // <-- it is true
if (authenticated) {
return fetch('http://localhost:9990/auth/realms/w/custom-sso-provider/sso', { headers: {
Authorization: `Bearer ${keycloakInstance.token}` } })
// else
请求本身似乎很好,Set-Cookie
正如我所料;这是响应标头:
我现在希望它们出现在 devtools > Application > cookie 中,但不幸的是没有 cookie 出现。为什么?我能做些什么呢?
解决方案
我错过credentials: 'include'
了fetch
电话:
return fetch('http://localhost:9990/auth/realms/w/custom-sso-provider/sso', { headers: { Authorization: `Bearer ${keycloakInstance.token}` }, credentials: 'include' })