Skip to content

Commit

Permalink
Add support for stateless user authentication in SimpleJWT (#1221)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
wmeints and tfranzel authored Apr 7, 2024
1 parent b1a34b0 commit 741ac4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 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 @@ -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"
10 changes: 8 additions & 2 deletions tests/contrib/test_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

try:
from rest_framework_simplejwt.authentication import (
JWTAuthentication, JWTTokenUserAuthentication,
JWTAuthentication, JWTStatelessUserAuthentication, JWTTokenUserAuthentication,
)
from rest_framework_simplejwt.views import (
TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, TokenVerifyView,
Expand All @@ -34,8 +34,14 @@ class X2Viewset(mixins.ListModelMixin, viewsets.GenericViewSet):
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")
Expand Down

0 comments on commit 741ac4c

Please sign in to comment.