Skip to content

Commit

Permalink
Add document authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
gongul committed Feb 22, 2021
1 parent 6b53554 commit 1611f6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions drf_spectacular/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# is the
'SERVE_INCLUDE_SCHEMA': True,
'SERVE_PERMISSIONS': ['rest_framework.permissions.AllowAny'],
'SERVE_AUTHENTICATION': None,

# Dictionary of configurations to pass to the SwaggerUI({ ... })
# https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
Expand Down Expand Up @@ -120,6 +121,7 @@
IMPORT_STRINGS = [
'SCHEMA_AUTHENTICATION_CLASSES',
'DEFAULT_GENERATOR_CLASS',
'SERVE_AUTHENTICATION',
'SERVE_PERMISSIONS',
'POSTPROCESSING_HOOKS',
'PREPROCESSING_HOOKS',
Expand Down
5 changes: 4 additions & 1 deletion drf_spectacular/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.settings import api_settings
from rest_framework.views import APIView

from drf_spectacular.plumbing import get_relative_url, set_query_parameters
Expand Down Expand Up @@ -42,7 +43,7 @@ class SpectacularAPIView(APIView):
OpenApiYamlRenderer, OpenApiYamlRenderer2, OpenApiJsonRenderer, OpenApiJsonRenderer2
]
permission_classes = spectacular_settings.SERVE_PERMISSIONS

authentication_classes = spectacular_settings.SERVE_AUTHENTICATION or api_settings.DEFAULT_AUTHENTICATION_CLASSES
generator_class = spectacular_settings.DEFAULT_GENERATOR_CLASS
serve_public = spectacular_settings.SERVE_PUBLIC
urlconf = spectacular_settings.SERVE_URLCONF
Expand Down Expand Up @@ -76,6 +77,7 @@ class SpectacularJSONAPIView(SpectacularAPIView):
class SpectacularSwaggerView(APIView):
renderer_classes = [TemplateHTMLRenderer]
permission_classes = spectacular_settings.SERVE_PERMISSIONS
authentication_classes = spectacular_settings.SERVE_AUTHENTICATION or api_settings.DEFAULT_AUTHENTICATION_CLASSES
url_name = 'schema'
url = None
template_name = 'drf_spectacular/swagger_ui.html'
Expand Down Expand Up @@ -140,6 +142,7 @@ def get(self, request, *args, **kwargs):
class SpectacularRedocView(APIView):
renderer_classes = [TemplateHTMLRenderer]
permission_classes = spectacular_settings.SERVE_PERMISSIONS
authentication_classes = spectacular_settings.SERVE_AUTHENTICATION or api_settings.DEFAULT_AUTHENTICATION_CLASSES
url_name = 'schema'
url = None
template_name = 'drf_spectacular/redoc.html'
Expand Down

0 comments on commit 1611f6f

Please sign in to comment.