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 overriding access token class #529

Merged
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: 7 additions & 6 deletions rest_framework_simplejwt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ def __init__(self, *args, **kwargs):
)


class AccessToken(Token):
token_type = "access"
lifetime = api_settings.ACCESS_TOKEN_LIFETIME


class RefreshToken(BlacklistMixin, Token):
token_type = "refresh"
lifetime = api_settings.REFRESH_TOKEN_LIFETIME
Expand All @@ -285,6 +290,7 @@ class RefreshToken(BlacklistMixin, Token):
api_settings.JTI_CLAIM,
"jti",
)
access_token_class = AccessToken

@property
def access_token(self):
Expand All @@ -293,7 +299,7 @@ def access_token(self):
claims present in this refresh token to the new access token except
those claims listed in the `no_copy_claims` attribute.
"""
access = AccessToken()
access = self.access_token_class()

# Use instantiation time of refresh token as relative timestamp for
# access token "exp" claim. This ensures that both a refresh and
Expand All @@ -310,11 +316,6 @@ def access_token(self):
return access


class AccessToken(Token):
token_type = "access"
lifetime = api_settings.ACCESS_TOKEN_LIFETIME


class UntypedToken(Token):
token_type = "untyped"
lifetime = timedelta(seconds=0)
Expand Down