diff --git a/drf_spectacular/contrib/rest_framework_simplejwt.py b/drf_spectacular/contrib/rest_framework_simplejwt.py index 10aaaaf7..ad076a08 100644 --- a/drf_spectacular/contrib/rest_framework_simplejwt.py +++ b/drf_spectacular/contrib/rest_framework_simplejwt.py @@ -65,3 +65,7 @@ def get_security_definition(self, auto_schema): 'scheme': 'bearer', 'bearerFormat': api_settings.AUTH_HEADER_TYPES[0], } + + +class SimpleJWTTokenUserScheme(SimpleJWTScheme): + target_class = 'rest_framework_simplejwt.authentication.JWTTokenUserAuthentication' diff --git a/tests/contrib/test_simplejwt.py b/tests/contrib/test_simplejwt.py index d678e62f..c4b442a0 100644 --- a/tests/contrib/test_simplejwt.py +++ b/tests/contrib/test_simplejwt.py @@ -5,7 +5,9 @@ from tests import assert_schema, generate_schema try: - from rest_framework_simplejwt.authentication import JWTAuthentication + from rest_framework_simplejwt.authentication import ( + JWTAuthentication, JWTTokenUserAuthentication, + ) from rest_framework_simplejwt.views import ( TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, ) @@ -23,10 +25,17 @@ class XViewset(mixins.ListModelMixin, viewsets.GenericViewSet): required_scopes = ['x:read', 'x:write'] +class X2Viewset(mixins.ListModelMixin, viewsets.GenericViewSet): + serializer_class = XSerializer + authentication_classes = [JWTTokenUserAuthentication] + required_scopes = ['x:read', 'x:write'] + + @pytest.mark.contrib('rest_framework_simplejwt') -def test_simplejwt(no_warnings): +@pytest.mark.parametrize('view', [XViewset, X2Viewset]) +def test_simplejwt(no_warnings, view): router = routers.SimpleRouter() - router.register('x', XViewset, basename="x") + router.register('x', view, basename="x") urlpatterns = [ *router.urls,