Authentication in Django DRF viewset (app) #3910
Replies: 6 comments 2 replies
-
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.
-
Hi pennersr. I have decided to move towards the simplejwt package for more fine tuned control over the jwt tokens like refresh and access tokens and an easy way to set expiry etc. How can I get the implmentation of the token strategy to work correctly.
Currently this is my code for SimpleJWTTokenStrategy and it works for new (simple-jwt) access token but there is no way to tell django allauth about my new (simple-jwt) refresh token. Is there a better way of implementing this instead of parking the access and refresh token under the access key? Thanks in advance. Your help is greatly appreciated! |
Beta Was this translation helpful? Give feedback.
-
thanks! working well! closing this. |
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