首页 > 解决方案 > httponly cookie 未设置

问题描述

有这个设置:

用户可以通过将用户名 + 密码发送到以下地址“登录”/获取 SPA 上的令牌:

http://localhost:9990/auth/realms/w/protocol/openid-connect/token

然后我在 auth-server 上调用另一个 url,它应该设置 keycloak 需要 SSO/remember-me 的 cookie(它应该设置一些HttpOnlycookie):

.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 出现。为什么?我能做些什么呢?

标签: cookiessingle-sign-onkeycloak

解决方案


我错过credentials: 'include'fetch电话:

return fetch('http://localhost:9990/auth/realms/w/custom-sso-provider/sso', { headers: { Authorization: `Bearer ${keycloakInstance.token}` }, credentials: 'include' })

推荐阅读