Skip to content

Commit 741ac4c

Browse files
wmeintstfranzel
andauthored
Add support for stateless user authentication in SimpleJWT (#1221)
* Add support for stateless user authentication in SimpleJWT * Add additional viewset to verify simpleJWT extension * Fix linting errors * Sort imports * make isort happy --------- Co-authored-by: T. Franzel <tfranzel@users.noreply.github.com>
1 parent b1a34b0 commit 741ac4c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

drf_spectacular/contrib/rest_framework_simplejwt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ def get_security_definition(self, auto_schema):
8181

8282
class SimpleJWTTokenUserScheme(SimpleJWTScheme):
8383
target_class = 'rest_framework_simplejwt.authentication.JWTTokenUserAuthentication'
84+
85+
86+
class SimpleJWTStatelessUserScheme(SimpleJWTScheme):
87+
target_class = "rest_framework_simplejwt.authentication.JWTStatelessUserAuthentication"

tests/contrib/test_simplejwt.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
try:
1010
from rest_framework_simplejwt.authentication import (
11-
JWTAuthentication, JWTTokenUserAuthentication,
11+
JWTAuthentication, JWTStatelessUserAuthentication, JWTTokenUserAuthentication,
1212
)
1313
from rest_framework_simplejwt.views import (
1414
TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, TokenVerifyView,
@@ -34,8 +34,14 @@ class X2Viewset(mixins.ListModelMixin, viewsets.GenericViewSet):
3434
required_scopes = ['x:read', 'x:write']
3535

3636

37+
class X3Viewset(mixins.ListModelMixin, viewsets.GenericViewSet):
38+
serializer_class = XSerializer
39+
authentication_classes = [JWTStatelessUserAuthentication]
40+
required_scopes = ['x:read', 'x:write']
41+
42+
3743
@pytest.mark.contrib('rest_framework_simplejwt')
38-
@pytest.mark.parametrize('view', [XViewset, X2Viewset])
44+
@pytest.mark.parametrize('view', [XViewset, X2Viewset, X3Viewset])
3945
def test_simplejwt(no_warnings, view):
4046
router = routers.SimpleRouter()
4147
router.register('x', view, basename="x")

0 commit comments

Comments
 (0)