-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
5 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
from djoser.views import TokenDestroyView | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
from rest_framework.status import HTTP_204_NO_CONTENT | ||
from rest_framework.views import APIView | ||
from rest_framework_simplejwt.tokens import SlidingToken | ||
|
||
from custom_auth.jwt_cookie.constants import JWT_SLIDING_COOKIE_KEY | ||
|
||
|
||
class JWTSlidingTokenLogoutView(APIView): | ||
""" | ||
This view only invalidates the JWT cookie. | ||
Currently, for clients which use token authentication, it's a no-op view. | ||
""" | ||
|
||
class JWTSlidingTokenLogoutView(TokenDestroyView): | ||
def post(self, request: Request) -> Response: | ||
response = Response(status=HTTP_204_NO_CONTENT) | ||
if isinstance(request.auth, SlidingToken): | ||
request.auth.blacklist() | ||
response = super().post(request) | ||
if isinstance(jwt_token := request.auth, SlidingToken): | ||
jwt_token.blacklist() | ||
response.delete_cookie(JWT_SLIDING_COOKIE_KEY) | ||
return response |