Skip to content

Commit

Permalink
bugfix Simple JWT token refresh #232
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Dec 15, 2020
1 parent e43ad2a commit 6cd3cc8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions drf_spectacular/contrib/rest_framework_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ def map_serializer(self, auto_schema, direction):
return auto_schema._map_serializer(Fixed, direction)


class TokenRefreshSerializerExtension(OpenApiSerializerExtension):
target_class = 'rest_framework_simplejwt.serializers.TokenRefreshSerializer'

def map_serializer(self, auto_schema, direction):
from rest_framework_simplejwt.settings import api_settings

if api_settings.ROTATE_REFRESH_TOKENS:
class Fixed(serializers.Serializer):
access = serializers.CharField(read_only=True)
refresh = serializers.CharField()
else:
class Fixed(serializers.Serializer):
access = serializers.CharField(read_only=True)
refresh = serializers.CharField(write_only=True)

return auto_schema._map_serializer(Fixed, direction)


class SimpleJWTScheme(OpenApiAuthenticationExtension):
target_class = 'rest_framework_simplejwt.authentication.JWTAuthentication'
name = 'jwtAuth'
Expand Down
5 changes: 5 additions & 0 deletions tests/contrib/test_rest_auth_token.yml
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,14 @@ components:
TokenRefresh:
type: object
properties:
access:
type: string
readOnly: true
refresh:
type: string
writeOnly: true
required:
- access
- refresh
TokenVerify:
type: object
Expand Down
5 changes: 5 additions & 0 deletions tests/contrib/test_simplejwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ components:
TokenRefresh:
type: object
properties:
access:
type: string
readOnly: true
refresh:
type: string
writeOnly: true
required:
- access
- refresh
X:
type: object
Expand Down

0 comments on commit 6cd3cc8

Please sign in to comment.