Skip to content

Instantly share code, notes, and snippets.

@ManotLuijiu
Created December 12, 2023 03:26
Show Gist options
  • Save ManotLuijiu/dd6fc94148b25602c8ab413cea9129b1 to your computer and use it in GitHub Desktop.
Save ManotLuijiu/dd6fc94148b25602c8ab413cea9129b1 to your computer and use it in GitHub Desktop.
users -> authentication.py
from django.conf import settings
from rest_framework_simplejwt.authentication import JWTAuthentication
class CustomJWTAuthentication(JWTAuthentication):
def authenticate(self, request):
try:
header = self.get_header(request)
if header is None:
raw_token = request.COOKIES.get(settings.AUTH_COOKIE)
else:
raw_token = self.get_raw_token(header)
if raw_token is None:
return None
validated_token = self.get_validated_token(raw_token)
return self.get_user(validated_token), validated_token
except Exception:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment