Currently, I have the login functionality working on my web app, after I make a login request the server responds with a JSON object that contains 2 tokens:
This is the login function:
async function login() {
const data = {
"email": "user1@gmail.com",
"password": "testPassword123"
}
const response = await Backend.post('auth/login/', data)
console.log(response.data)
}
And this is the response:
{
"access": "access_token_here",
"refresh": "refresh_token_here"
}
According to Postman, this response also contains 3 cookies:
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;
To make a request to a protected endpoint in the server, I can send the access_token as a cookie or as a Bearer token. My understanding is that storing these tokens in Local Storage is not very secure.
So how can I store them in httpOnly cookie? Or is there a better way of dealing with this?
My backend server is using Django Rest Framework.