首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有设置httponly cookie

没有设置httponly cookie
EN

Stack Overflow用户
提问于 2020-10-20 07:32:40
回答 1查看 513关注 0票数 0

有这样的设置:

localhost:3000

  • auth server (keycloak):localhost:9990
  • 后端:localhost:8080
  • 前端

用户可以通过向以下用户发送用户名+密码在SPA上“登录”/获取令牌:

代码语言:javascript
复制
http://localhost:9990/auth/realms/w/protocol/openid-connect/token

然后,我在auth服务器上调用另一个url,该url应该设置SSO/ HttpOnly -me(它应该设置一些cookie)所需的keycloak所需的cookie:

代码语言:javascript
复制
.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 > cookies中,但不幸的是,没有出现cookie。为什么?我能做些什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-20 07:54:14

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

代码语言:javascript
复制
return fetch('http://localhost:9990/auth/realms/w/custom-sso-provider/sso', { headers: { Authorization: `Bearer ${keycloakInstance.token}` }, credentials: 'include' })
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64440508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档