naturerobots / HSOS-SEP-PlantMap-2022

PlantMap Digital Logbook: A tool to support sustainable micro farming :link: https://naturerobots.github.io/HSOS-SEP-PlantMap-2022/
BSD 3-Clause "New" or "Revised" License
4 stars 5 forks source link

Feat/tokenauth #129

Closed Anafabula closed 2 years ago

Anafabula commented 2 years ago

Implements a simple token authentication scheme including enpoints /register, /login, /logout and /logoutall. /register and /login return a json object like this:

{
    "expiry": "2022-06-22T01:37:05.620954Z",
    "token": "22aae158f7e89b67bdcadab912933f29fe83d81affb0963a15b99e31c4ecdb01"
}

The token needs to be sent in the Authorization header with Token as a Prefix like this:

Authorization: Token 22aae158f7e89b67bdcadab912933f29fe83d81affb0963a15b99e31c4ecdb01

Authorization can be disabled for an endpoint for testing in the views.py by annotating the function with @permission_classes([AllowAny]) (Example here, uncomment the line).

The logged-in user is accessible in the backend via request.user.

closes #17 closes #113