This document is an overview of the endpoints for handling the authentication on the web page, and how they are used.
A diagram representing the flow of the program when managing authentication. As the authentication server does not send any tokens, but rather sets cookies with the token, the website only has to manage if the user is logged in our not, and give the user feedback based on this.
Tries to log in a user with given username and password. Sends this to login endpoint, and if it succeds an authentication cookie is set.
POST /api/auth/login/ HTTP/1.1
Content-Type: application/json
{
"username": "string",
"email": "user@example.com",
"password": "string"
}HTTP/1.1 200 OK
Set-Cookie: test=token_value; HttpOnly; SameSite=Strict; Secure;
Content-Type: application/json
{
"access": "string",
"refresh": "string",
"user": {
"pk": 0,
"username": "NnnbyRtlH0Mo11z6fO_Wr7CHJ9Cn9E6GWyHlNvbGXYLIxdZYba3GJ1ugAslyP8v",
"email": "user@example.com",
"first_name": "string",
"last_name": "string"
}
}HTTP/1.1 401 UnauthorizedShould be called when a user clicks on log out.
POST /api/auth/logout/ HTTP/1.1HTTP/1.1 200 OK
Content-Type: application/json
{
"detail": "string"
}Should be called when a request was not authenticated to try to get a new token if possible. If the request fails, the user should be redirected to the log in page.
POST /api/auth/token/refresh/ HTTP/1.1
Content-Type: application/json
{
"refresh": "string"
}HTTP/1.1 200 OK
Set-Cookie: test=token_value; HttpOnly; SameSite=Strict; Secure;
{
"access": "string"
}HTTP/1.1 401 UnauthorizedShould be called when the website loads to check if the user is authenticated.
POST /api/auth/token/verify/ HTTP/1.1
Content-Type: application/json
{
"token": "string"
}HTTP/1.1 200 OK
{ }HTTP/1.1 401 UnauthorizedWhen a user tries to request a resource which required authentication.
The response does not have to do anything, as long as the request is to the same domain as the website the cookie will automatically be sent.
HTTP/1.1 200 OKHTTP/1.1 401 UnauthorizedIf request failed, the website should try to refresh the token, and if this fails the user should be redirected to the login page.
