File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from typing import Optional , TypeVar
1+ from typing import Optional , TypeVar , Any
22
33from django .contrib .auth import get_user_model
44from django .contrib .auth .models import AbstractBaseUser
@@ -121,6 +121,9 @@ def get_validated_token(self, raw_token: bytes) -> Token:
121121 }
122122 )
123123
124+ def get_user_queryset (self , user_id : Any = None ) -> Optional [AuthUser ]:
125+ return self .user_model .objects .get (** {api_settings .USER_ID_FIELD : user_id })
126+
124127 def get_user (self , validated_token : Token ) -> AuthUser :
125128 """
126129 Attempts to find and return a user using the given validated token.
@@ -133,7 +136,9 @@ def get_user(self, validated_token: Token) -> AuthUser:
133136 ) from e
134137
135138 try :
136- user = self .user_model .objects .get (** {api_settings .USER_ID_FIELD : user_id })
139+ user = self .get_user_queryset (user_id )
140+ if not user :
141+ raise AuthenticationFailed (_ ("User not found" ), code = "user_not_found" )
137142 except self .user_model .DoesNotExist as e :
138143 raise AuthenticationFailed (
139144 _ ("User not found" ), code = "user_not_found"
You can’t perform that action at this time.
0 commit comments