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

Fixed issue #363 #565

Open
wants to merge 2 commits 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
16 changes: 16 additions & 0 deletions rest_framework_simplejwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
from rest_framework import exceptions, serializers
from rest_framework.exceptions import ValidationError

from .authentication import JWTAuthentication
from .settings import api_settings
from .tokens import RefreshToken, SlidingToken, UntypedToken
from .utils import datetime_from_epoch

if api_settings.ROTATE_REFRESH_TOKENS:
from .token_blacklist.models import OutstandingToken

if api_settings.BLACKLIST_AFTER_ROTATION:
from .token_blacklist.models import BlacklistedToken
Expand Down Expand Up @@ -118,6 +123,17 @@ def validate(self, attrs):
refresh.set_exp()
refresh.set_iat()

# Create OutstandingToken when rotate refresh token
auth = JWTAuthentication()
user = auth.get_user(validated_token=refresh)
OutstandingToken.objects.create(
user=user,
jti=refresh[api_settings.JTI_CLAIM],
token=str(refresh),
created_at=refresh.current_time,
expires_at=datetime_from_epoch(refresh["exp"]),
)

data["refresh"] = str(refresh)

return data
Expand Down