Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add document authentication #312

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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