未设置httponly cookie

时间:2020-10-20 07:32:40

标签: cookies single-sign-on keycloak

具有此设置:

  • 身份验证服务器(密钥斗篷):localhost:9990
  • 后端:localhost:8080
  • 前端(SPA):localhost:3000

用户可以通过将其用户名和密码发送至:来在SPA上“登录” /获取令牌。

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

然后,我在身份验证服务器上调用另一个URL,该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发生了,正如我所期望的那样;这是响应头:

response header

我现在希望它们出现在devtools>应用程序> cookie中,但是不幸的是没有cookie出现。为什么?那我该怎么办?

1 个答案:

答案 0 :(得分:0)

credentials: 'include'通话中我错过了fetch

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