File tree Expand file tree Collapse file tree 3 files changed +7
-10
lines changed
src/rest_framework_jwt/blacklist Expand file tree Collapse file tree 3 files changed +7
-10
lines changed Original file line number Diff line number Diff line change 55from rest_framework .response import Response
66from rest_framework .views import APIView
77
8- from rest_framework_jwt .blacklist .permissions import IsAuthenticatedAndNotBlacklisted
8+ from rest_framework_jwt .blacklist .permissions import IsNotBlacklisted
99from rest_framework_jwt .permissions import IsSuperUser
1010
1111
@@ -22,7 +22,7 @@ def get(self, request):
2222
2323
2424class BlacklistPermissionTestView (APIView ):
25- permission_classes = (IsAuthenticatedAndNotBlacklisted , )
25+ permission_classes = (IsNotBlacklisted , )
2626
2727 def get (self , request ):
2828 return Response ({'foo' : 'bar' })
Original file line number Diff line number Diff line change 128128REST_FRAMEWORK = {
129129 'DEFAULT_PERMISSION_CLASSES' : (
130130 'rest_framework.permissions.IsAuthenticated' ,
131- 'rest_framework_jwt.blacklist.permissions.IsAuthenticatedAndNotBlacklisted ' ,
131+ 'rest_framework_jwt.blacklist.permissions.IsNotBlacklisted ' ,
132132 ),
133133 'DEFAULT_AUTHENTICATION_CLASSES' : (
134134 'rest_framework_jwt.authentication.JSONWebTokenAuthentication' ,
Original file line number Diff line number Diff line change 1-
1+ from django . utils . encoding import force_str
22from rest_framework .permissions import BasePermission
33
44from rest_framework_jwt .blacklist .models import BlacklistedToken
55from rest_framework_jwt .settings import api_settings
66
77
8- class IsAuthenticatedAndNotBlacklisted (BasePermission ):
9- message = 'You are not authenticated or have been blacklisted.'
8+ class IsNotBlacklisted (BasePermission ):
9+ message = 'You have been blacklisted.'
1010
1111 def has_permission (self , request , view ):
12- if request .user and not request .user .is_authenticated :
13- return False
14-
1512 if api_settings .JWT_AUTH_COOKIE :
1613 token = request .COOKIES .get (api_settings .JWT_AUTH_COOKIE )
1714 else :
18- token = request .auth . decode ( 'utf-8' )
15+ token = force_str ( request .auth )
1916
2017 return not BlacklistedToken .objects .filter (token = token ).exists ()
You can’t perform that action at this time.
0 commit comments