目前,我的 Web 应用程序可以使用登录功能,在发出登录请求后,服务器会使用包含 2 个令牌的 JSON 对象进行响应:
这是登录功能:
async function login() {
const data = {
"email": "[email protected] /cdn-cgi/l/email-protection",
"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 或承载令牌发送。
我的理解是,将这些令牌存储在本地存储中并不是很安全。
那么如何将它们存储在 httpOnly cookie 中呢?或者有更好的方法来处理这个问题吗?
我的后端服务器使用 Django Rest Framework。