Skip to content

Commit

Permalink
bugfix missing auth extension for JWTTokenUserAuthentication #387
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed May 15, 2021
1 parent bddeed2 commit 4da04c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions drf_spectacular/contrib/rest_framework_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
15 changes: 12 additions & 3 deletions tests/contrib/test_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
Expand Down

0 comments on commit 4da04c2

Please sign in to comment.