Authentication in Django DRF viewset (app) #3910
Replies: 4 comments
-
Given that you are using using the 'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
], None of those are capable of mapping the As for the former, you will need to create a class as documented here https://www.django-rest-framework.org/api-guide/authentication/#custom-authentication and add that to your As for the latter, you can setup an allauth class DRFTokenStrategy(SessionTokenStrategy):
def create_access_token(self, request):
from rest_framework.authtoken.models import Token
token, created = Token.objects.get_or_create(user=request.user)
return token.key When the user authenticates, that |
Beta Was this translation helpful? Give feedback.
-
Thanks for your quick reply. It is working well! |
Beta Was this translation helpful? Give feedback.
-
My 2cts -- keep things as simple and stupid as possible and pick boring technology. Unless there are requirements where your project is split across multiple smaller services that need to authenticate in a stateless fashion, JWTs typically do not provide any benefit. |
Beta Was this translation helpful? Give feedback.
-
Thank you! Will consider your comment and revisit it only when we need it. |
Beta Was this translation helpful? Give feedback.
-
This is a django-allauth headless question.
Given that I authenticate over
_allauth/app/v1/auth/login
and extract the session token and prove that the authentication is successful on_allauth/app/v1/auth/session
using said token,How can my DRF viewset return
True
forrequest.user.is_authenticated
. Currently no matter what I do, the session header that I pass into the get request do not get translated into an authenticated user but they do exist as headers (can print them).views.py
settings.py
I searched through github issues, discussions, reddit etc. Couldnt find a solution. Tried adding
'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.TokenAuthentication'
inDEFAULT_AUTHENTICATION_CLASSES
, didnt work.Beta Was this translation helpful? Give feedback.
All reactions