Skip to content

Commit

Permalink
Merge pull request #513 from ngnpope/fix-simplejwt-verify
Browse files Browse the repository at this point in the history
Add extension for TokenVerifySerializer.
  • Loading branch information
tfranzel authored Sep 14, 2021
2 parents 3222198 + 4c8753b commit dd7020a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
10 changes: 10 additions & 0 deletions drf_spectacular/contrib/rest_framework_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class Fixed(serializers.Serializer):
return auto_schema._map_serializer(Fixed, direction)


class TokenVerifySerializerExtension(OpenApiSerializerExtension):
target_class = 'rest_framework_simplejwt.serializers.TokenVerifySerializer'

def map_serializer(self, auto_schema, direction):
Fixed = inline_serializer('Fixed', fields={
'token': 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
1 change: 1 addition & 0 deletions tests/contrib/test_rest_auth_token.yml
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ components:
properties:
token:
type: string
writeOnly: true
required:
- token
UserDetails:
Expand Down
3 changes: 2 additions & 1 deletion tests/contrib/test_simplejwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
JWTAuthentication, JWTTokenUserAuthentication,
)
from rest_framework_simplejwt.views import (
TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView,
TokenObtainPairView, TokenObtainSlidingView, TokenRefreshView, TokenVerifyView,
)
except ImportError:
JWTAuthentication = None
Expand Down Expand Up @@ -44,6 +44,7 @@ def test_simplejwt(no_warnings, view):
path('token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('token-sliding/', TokenObtainSlidingView.as_view(), name='token_obtain_sliding'),
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('token/verify/', TokenVerifyView.as_view(), name='token_verify'),
]

schema = generate_schema(None, patterns=urlpatterns)
Expand Down
35 changes: 35 additions & 0 deletions tests/contrib/test_simplejwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,33 @@ paths:
schema:
$ref: '#/components/schemas/TokenRefresh'
description: ''
/token/verify/:
post:
operationId: token_verify_create
description: |-
Takes a token and indicates if it is valid. This view provides no
information about a token's fitness for a particular use.
tags:
- token
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TokenVerify'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/TokenVerify'
multipart/form-data:
schema:
$ref: '#/components/schemas/TokenVerify'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/TokenVerify'
description: ''
/x/:
get:
operationId: x_list
Expand Down Expand Up @@ -152,6 +179,14 @@ components:
required:
- access
- refresh
TokenVerify:
type: object
properties:
token:
type: string
writeOnly: true
required:
- token
X:
type: object
properties:
Expand Down

0 comments on commit dd7020a

Please sign in to comment.