I am using Django Rest Framework and i\'ve included a 3rd party package called REST framework JWT Auth. It returns a token when you send a username/password to a certain route.
For me, this worked as RestFrameworkJWT is no longer maintained.
So I used the rest_framework_simplejw
package.
from rest_framework_simplejwt.backends import TokenBackend
token = request.META.get('HTTP_AUTHORIZATION', " ").split(' ')[1]
data = {'token': token}
try:
valid_data = TokenBackend(algorithm='HS256').decode(token,verify=False)
user = valid_data['user']
request.user = user
except ValidationError as v:
print("validation error", v)