Created
December 12, 2023 03:26
-
-
Save ManotLuijiu/dd6fc94148b25602c8ab413cea9129b1 to your computer and use it in GitHub Desktop.
users -> authentication.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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