Skip to content

Commit 027c79c

Browse files
fix: Token.outstand forces users to install blacklist app (#884)
1 parent 00de028 commit 027c79c

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

rest_framework_simplejwt/tokens.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,30 +205,12 @@ def check_exp(
205205
if claim_time <= current_time - leeway:
206206
raise TokenError(format_lazy(_("Token '{}' claim has expired"), claim))
207207

208-
def outstand(self) -> OutstandingToken:
208+
def outstand(self) -> Optional[OutstandingToken]:
209209
"""
210210
Ensures this token is included in the outstanding token list and
211211
adds it to the outstanding token list if not.
212212
"""
213-
jti = self.payload[api_settings.JTI_CLAIM]
214-
exp = self.payload["exp"]
215-
user_id = self.payload.get(api_settings.USER_ID_CLAIM)
216-
User = get_user_model()
217-
try:
218-
user = User.objects.get(**{api_settings.USER_ID_FIELD: user_id})
219-
except User.DoesNotExist:
220-
user = None
221-
222-
# Ensure outstanding token exists with given jti
223-
return OutstandingToken.objects.get_or_create(
224-
jti=jti,
225-
defaults={
226-
"user": user,
227-
"created_at": self.current_time,
228-
"token": str(self),
229-
"expires_at": datetime_from_epoch(exp),
230-
},
231-
)
213+
return None
232214

233215
@classmethod
234216
def for_user(cls: type[T], user: AuthUser) -> T:
@@ -325,6 +307,31 @@ def blacklist(self) -> BlacklistedToken:
325307

326308
return BlacklistedToken.objects.get_or_create(token=token)
327309

310+
def outstand(self) -> Optional[OutstandingToken]:
311+
"""
312+
Ensures this token is included in the outstanding token list and
313+
adds it to the outstanding token list if not.
314+
"""
315+
jti = self.payload[api_settings.JTI_CLAIM]
316+
exp = self.payload["exp"]
317+
user_id = self.payload.get(api_settings.USER_ID_CLAIM)
318+
User = get_user_model()
319+
try:
320+
user = User.objects.get(**{api_settings.USER_ID_FIELD: user_id})
321+
except User.DoesNotExist:
322+
user = None
323+
324+
# Ensure outstanding token exists with given jti
325+
return OutstandingToken.objects.get_or_create(
326+
jti=jti,
327+
defaults={
328+
"user": user,
329+
"created_at": self.current_time,
330+
"token": str(self),
331+
"expires_at": datetime_from_epoch(exp),
332+
},
333+
)
334+
328335
@classmethod
329336
def for_user(cls: type[T], user: AuthUser) -> T:
330337
"""

0 commit comments

Comments
 (0)