From b228b38e92cdbb0a36da35377e9fb22ea0a8e923 Mon Sep 17 00:00:00 2001 From: "willem.meints@gmail.com" <1550763+wmeints@users.noreply.github.com> Date: Sat, 6 Apr 2024 08:55:23 +0200 Subject: [PATCH 1/5] Add support for stateless user authentication in SimpleJWT --- drf_spectacular/contrib/rest_framework_simplejwt.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drf_spectacular/contrib/rest_framework_simplejwt.py b/drf_spectacular/contrib/rest_framework_simplejwt.py index 3decfdec..460d42b9 100644 --- a/drf_spectacular/contrib/rest_framework_simplejwt.py +++ b/drf_spectacular/contrib/rest_framework_simplejwt.py @@ -81,3 +81,7 @@ def get_security_definition(self, auto_schema): class SimpleJWTTokenUserScheme(SimpleJWTScheme): target_class = 'rest_framework_simplejwt.authentication.JWTTokenUserAuthentication' + + +class SimpleJWTStatelessUserScheme(SimpleJWTScheme): + target_class = "rest_framework_simplejwt.authentication.JWTStatelessUserAuthentication" From c0a27e23c7d68d9e10f95664eeec11ac6884acbf Mon Sep 17 00:00:00 2001 From: "willem.meints@gmail.com" <1550763+wmeints@users.noreply.github.com> Date: Sat, 6 Apr 2024 09:44:04 +0200 Subject: [PATCH 2/5] Add additional viewset to verify simpleJWT extension --- tests/contrib/test_simplejwt.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/contrib/test_simplejwt.py b/tests/contrib/test_simplejwt.py index bb7b8ad2..ae710fa9 100644 --- a/tests/contrib/test_simplejwt.py +++ b/tests/contrib/test_simplejwt.py @@ -8,7 +8,7 @@ try: from rest_framework_simplejwt.authentication import ( - JWTAuthentication, JWTTokenUserAuthentication, + JWTAuthentication, JWTTokenUserAuthentication, JWTStatelessUserAuthentication ) from rest_framework_simplejwt.views import ( TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, TokenVerifyView, @@ -33,9 +33,14 @@ class X2Viewset(mixins.ListModelMixin, viewsets.GenericViewSet): authentication_classes = [JWTTokenUserAuthentication] required_scopes = ['x:read', 'x:write'] +class X3Viewset(mixins.ListModelMixin, viewsets.GenericViewSet): + serializer_class = XSerializer + authentication_classes = [JWTStatelessUserAuthentication] + required_scopes = ['x:read', 'x:write'] + @pytest.mark.contrib('rest_framework_simplejwt') -@pytest.mark.parametrize('view', [XViewset, X2Viewset]) +@pytest.mark.parametrize('view', [XViewset, X2Viewset, X3Viewset]) def test_simplejwt(no_warnings, view): router = routers.SimpleRouter() router.register('x', view, basename="x") From d74264bdb80d2df3200ae549e8731c42a1347104 Mon Sep 17 00:00:00 2001 From: "willem.meints@gmail.com" <1550763+wmeints@users.noreply.github.com> Date: Sat, 6 Apr 2024 10:27:02 +0200 Subject: [PATCH 3/5] Fix linting errors --- tests/contrib/test_simplejwt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/contrib/test_simplejwt.py b/tests/contrib/test_simplejwt.py index ae710fa9..2e0a8b8a 100644 --- a/tests/contrib/test_simplejwt.py +++ b/tests/contrib/test_simplejwt.py @@ -33,6 +33,7 @@ class X2Viewset(mixins.ListModelMixin, viewsets.GenericViewSet): authentication_classes = [JWTTokenUserAuthentication] required_scopes = ['x:read', 'x:write'] + class X3Viewset(mixins.ListModelMixin, viewsets.GenericViewSet): serializer_class = XSerializer authentication_classes = [JWTStatelessUserAuthentication] From 84d86bdc53d965f13284301f951c6721281654f7 Mon Sep 17 00:00:00 2001 From: "willem.meints@gmail.com" <1550763+wmeints@users.noreply.github.com> Date: Sat, 6 Apr 2024 19:49:38 +0200 Subject: [PATCH 4/5] Sort imports --- tests/contrib/test_simplejwt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/test_simplejwt.py b/tests/contrib/test_simplejwt.py index 2e0a8b8a..8e184233 100644 --- a/tests/contrib/test_simplejwt.py +++ b/tests/contrib/test_simplejwt.py @@ -8,7 +8,7 @@ try: from rest_framework_simplejwt.authentication import ( - JWTAuthentication, JWTTokenUserAuthentication, JWTStatelessUserAuthentication + JWTAuthentication, JWTStatelessUserAuthentication, JWTTokenUserAuthentication ) from rest_framework_simplejwt.views import ( TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, TokenVerifyView, From 5c8fee1c9c402cbd268edcdaca604d3c6138427d Mon Sep 17 00:00:00 2001 From: "T. Franzel" Date: Sun, 7 Apr 2024 12:38:35 +0200 Subject: [PATCH 5/5] make isort happy --- tests/contrib/test_simplejwt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/test_simplejwt.py b/tests/contrib/test_simplejwt.py index 8e184233..690414c4 100644 --- a/tests/contrib/test_simplejwt.py +++ b/tests/contrib/test_simplejwt.py @@ -8,7 +8,7 @@ try: from rest_framework_simplejwt.authentication import ( - JWTAuthentication, JWTStatelessUserAuthentication, JWTTokenUserAuthentication + JWTAuthentication, JWTStatelessUserAuthentication, JWTTokenUserAuthentication, ) from rest_framework_simplejwt.views import ( TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, TokenVerifyView,