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

fix: Make don't create and save new refresh token with None when refr… #634

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
32 changes: 21 additions & 11 deletions dj_rest_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,34 @@ def logout(self, request):

unset_jwt_cookies(response)

if 'rest_framework_simplejwt.token_blacklist' in settings.INSTALLED_APPS:
if "rest_framework_simplejwt.token_blacklist" in settings.INSTALLED_APPS:
# add refresh token to blacklist
try:
token: RefreshToken = RefreshToken(None)
if api_settings.JWT_AUTH_HTTPONLY:
try:
token = RefreshToken(request.COOKIES[api_settings.JWT_AUTH_REFRESH_COOKIE])
except KeyError:
response.data = {'detail': _('Refresh token was not included in cookie data.')}
token = request.COOKIES.get(
api_settings.JWT_AUTH_REFRESH_COOKIE
)
if token:
RefreshToken(token).blacklist()
else:
response.data = {
"detail": _(
"Refresh token was not included in cookie data."
)
}
response.status_code = status.HTTP_401_UNAUTHORIZED
else:
try:
token = RefreshToken(request.data['refresh'])
except KeyError:
response.data = {'detail': _('Refresh token was not included in request data.')}
token = request.data.get("refresh")
if token:
RefreshToken(token).blacklist()
else:
response.data = {
"detail": _(
"Refresh token was not included in request data."
)
}
response.status_code = status.HTTP_401_UNAUTHORIZED

token.blacklist()
except (TokenError, AttributeError, TypeError) as error:
if hasattr(error, 'args'):
if 'Token is blacklisted' in error.args or 'Token is invalid or expired' in error.args:
Expand Down