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

Allow none jti claim token type claim #567

Merged
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions rest_framework_simplejwt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,18 @@ def verify(self):
# claim. We don't want any zombie tokens walking around.
self.check_exp()

# Ensure token id is present
if api_settings.JTI_CLAIM not in self.payload:
# If the defaults are not None then we should enforce the
# requirement of these settings.As above, the spec labels
# these as optional.
if (
api_settings.JTI_CLAIM is not None
and api_settings.JTI_CLAIM not in self.payload
):
raise TokenError(_("Token has no id"))

self.verify_token_type()
if api_settings.TOKEN_TYPE_CLAIM is not None:

self.verify_token_type()

def verify_token_type(self):
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ def test_set_jti(self):
self.assertIn("jti", token)
self.assertNotEqual(old_jti, token["jti"])

def test_optional_jti(self):
with override_api_settings(JTI_CLAIM=None):
token = MyToken()
self.assertNotIn("jti", token)

def test_optional_type_token(self):
with override_api_settings(TOKEN_TYPE_CLAIM=None):
token = MyToken()
self.assertNotIn("type", token)

def test_set_exp(self):
now = make_utc(datetime(year=2000, month=1, day=1))

Expand Down