我正在尝试通过我正在编写的API的响应传递HttpOnly
cookie。目的是为了使Cookie像刷新令牌一样,目的是silent refresh用于React中的SPA。
在我的控制器方法中,我有以下代码:
response.set_cookie(
:foo,{
value: 'testing',expires: 7.days.from_now,path: '/api/v1/auth',secure: true,httponly: true
}
)
我正在使用fetch
这样的命令对此操作进行发布请求:
fetch("http://localhost:3001/api/v1/auth",{
method: 'POST',headers: {
'Content-Type': 'application/json'
},body: JSON.stringify({
email: 'aaron@example.com',password: '123456',})
})
不确定这是否重要,但我想知道在XHR响应中传递cookie是否无效?但是,正如您在我的回复中看到的那样,这似乎正在起作用:
Set-Cookie: foo=testing; path=/api/v1/auth; expires=Sun,26 Jan 2020 05:15:30 GMT; secure; HttpOnly
但是,我没有在Application -> Cookies
下设置cookie:
为澄清起见,React应用程序位于localhost:3000
上,而Rails后端正在监听localhost:3001
。
有什么想法吗?