【发布时间】:2021-02-11 14:43:19
【问题描述】:
目前,我的 Web 应用程序具有登录功能,在我发出登录请求后,服务器会使用包含 2 个令牌的 JSON 对象进行响应:
这是登录功能:
async function login() {
const data = {
"email": "user1@gmail.com",
"password": "testPassword123"
}
const response = await Backend.post('auth/login/', data)
console.log(response.data)
}
这是回应:
{
"access": "access_token_here",
"refresh": "refresh_token_here"
}
根据 Postman 的说法,这个响应还包含 3 个 cookie:
1) access_token=access_token_here; Path=/; Domain=localhost; HttpOnly; Expires=Thu, 29 Oct 2020 06:49:56 GMT;
2) csrftoken=csrf_token_here; Path=/; Domain=localhost; Expires=Thu, 28 Oct 2021 06:44:56 GMT;
3) sessionid=session_id_here; Path=/; Domain=localhost; HttpOnly; Expires=Thu, 12 Nov 2020 06:44:56 GMT;
要向服务器中的受保护端点发出请求,我可以将 access_token 作为 cookie 或作为 Bearer 令牌发送。 我的理解是,将这些令牌存储在 Local Storage 中并不是很安全。
那么如何将它们存储在 httpOnly cookie 中?或者有没有更好的处理方法?
我的后端服务器正在使用 Django Rest Framework。
【问题讨论】:
标签: reactjs django-rest-framework jwt django-react