mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-12-04 14:53:43 +03:00
attempt to blacklist token if no JWT_AUTH_COOKIE is found
This commit is contained in:
parent
26b6e22043
commit
241011a353
|
@ -142,20 +142,20 @@ class LogoutView(APIView):
|
||||||
cookie_name = getattr(settings, 'JWT_AUTH_COOKIE', None)
|
cookie_name = getattr(settings, 'JWT_AUTH_COOKIE', None)
|
||||||
if cookie_name:
|
if cookie_name:
|
||||||
response.delete_cookie(cookie_name)
|
response.delete_cookie(cookie_name)
|
||||||
# add refresh token to blacklist
|
else:
|
||||||
try:
|
# add refresh token to blacklist
|
||||||
token = RefreshToken(request.data['refresh'])
|
try:
|
||||||
token.blacklist()
|
token = RefreshToken(request.data['refresh'])
|
||||||
except KeyError:
|
token.blacklist()
|
||||||
response = Response({"detail": _("Refresh token was not included.")},
|
except KeyError:
|
||||||
status=status.HTTP_401_UNAUTHORIZED)
|
response = Response({"detail": _("Refresh token was not included.")},
|
||||||
except TokenError as e:
|
status=status.HTTP_401_UNAUTHORIZED)
|
||||||
if e.args[0] == 'Token is blacklisted':
|
except TokenError as e:
|
||||||
response = Response({"detail": _("Token is already blacklisted.")},
|
if e.args[0] == 'Token is blacklisted':
|
||||||
status=status.HTTP_404_NOT_FOUND)
|
response = Response({"detail": _("Token is already blacklisted.")},
|
||||||
except AttributeError as e:
|
status=status.HTTP_404_NOT_FOUND)
|
||||||
# warn user blacklist is not enabled if not using JWT_AUTH_COOKIE
|
except AttributeError as e:
|
||||||
if not cookie_name:
|
# warn user blacklist is not enabled
|
||||||
if e.args[0] == "'RefreshToken' object has no attribute 'blacklist'":
|
if e.args[0] == "'RefreshToken' object has no attribute 'blacklist'":
|
||||||
response = Response({"detail": _("Blacklist is not enabled in INSTALLED_APPS.")},
|
response = Response({"detail": _("Blacklist is not enabled in INSTALLED_APPS.")},
|
||||||
status=status.HTTP_501_NOT_IMPLEMENTED)
|
status=status.HTTP_501_NOT_IMPLEMENTED)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user