Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to check_exp() for return result #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions rest_framework_simplejwt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def set_exp(self, claim='exp', from_time=None, lifetime=None):

self.payload[claim] = datetime_to_epoch(from_time + lifetime)

def check_exp(self, claim='exp', current_time=None):
def check_exp(self, claim='exp', current_time=None, return_result=False):
"""
Checks whether a timestamp value in the given claim has passed (since
the given datetime value in `current_time`). Raises a TokenError with
Expand All @@ -150,7 +150,10 @@ def check_exp(self, claim='exp', current_time=None):

claim_time = datetime_from_epoch(claim_value)
if claim_time <= current_time:
raise TokenError(format_lazy(_("Token '{}' claim has expired"), claim))
if return_result is True:
return True
else:
raise TokenError(format_lazy(_("Token '{}' claim has expired"), claim))

@classmethod
def for_user(cls, user):
Expand Down