From 098fe7e119e4a0a8d78d1c847e7bdd0c519c818c Mon Sep 17 00:00:00 2001 From: Georg Krause Date: Fri, 15 Jul 2022 20:14:19 +0200 Subject: [PATCH] Fix swagger generation --- api/config/__init__.py | 1 + api/config/schema.py | 26 ++++++++++++++++++++++++++ api/config/settings/local.py | 27 --------------------------- 3 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 api/config/schema.py diff --git a/api/config/__init__.py b/api/config/__init__.py index e69de29bb..d03194c8c 100644 --- a/api/config/__init__.py +++ b/api/config/__init__.py @@ -0,0 +1 @@ +import config.schema diff --git a/api/config/schema.py b/api/config/schema.py new file mode 100644 index 000000000..a5e83882a --- /dev/null +++ b/api/config/schema.py @@ -0,0 +1,26 @@ +from drf_spectacular.contrib.django_oauth_toolkit import OpenApiAuthenticationExtension + +class CustomOAuthExt(OpenApiAuthenticationExtension): + target_class = "funkwhale_api.common.authentication.OAuth2Authentication" + name = "oauth2" + + def get_security_definition(self, auto_schema): + from oauth2_provider.scopes import get_scopes_backend + + from drf_spectacular.settings import spectacular_settings + + flows = {} + for flow_type in spectacular_settings.OAUTH2_FLOWS: + flows[flow_type] = {} + if flow_type in ("implicit", "authorizationCode"): + flows[flow_type][ + "authorizationUrl" + ] = spectacular_settings.OAUTH2_AUTHORIZATION_URL + if flow_type in ("password", "clientCredentials", "authorizationCode"): + flows[flow_type]["tokenUrl"] = spectacular_settings.OAUTH2_TOKEN_URL + if spectacular_settings.OAUTH2_REFRESH_URL: + flows[flow_type]["refreshUrl"] = spectacular_settings.OAUTH2_REFRESH_URL + scope_backend = get_scopes_backend() + flows[flow_type]["scopes"] = scope_backend.get_all_scopes() + + return {"type": "oauth2", "flows": flows} diff --git a/api/config/settings/local.py b/api/config/settings/local.py index f0a64f0fa..1f596a5e2 100644 --- a/api/config/settings/local.py +++ b/api/config/settings/local.py @@ -10,7 +10,6 @@ Local settings from .common import * # noqa from funkwhale_api import __version__ as funkwhale_version -from drf_spectacular.contrib.django_oauth_toolkit import OpenApiAuthenticationExtension # DEBUG @@ -143,29 +142,3 @@ MIDDLEWARE = ( "funkwhale_api.common.middleware.ProfilerMiddleware", "funkwhale_api.common.middleware.PymallocMiddleware", ) + MIDDLEWARE - - -class CustomOAuthExt(OpenApiAuthenticationExtension): - target_class = "funkwhale_api.common.authentication.OAuth2Authentication" - name = "oauth2" - - def get_security_definition(self, auto_schema): - from oauth2_provider.scopes import get_scopes_backend - - from drf_spectacular.settings import spectacular_settings - - flows = {} - for flow_type in spectacular_settings.OAUTH2_FLOWS: - flows[flow_type] = {} - if flow_type in ("implicit", "authorizationCode"): - flows[flow_type][ - "authorizationUrl" - ] = spectacular_settings.OAUTH2_AUTHORIZATION_URL - if flow_type in ("password", "clientCredentials", "authorizationCode"): - flows[flow_type]["tokenUrl"] = spectacular_settings.OAUTH2_TOKEN_URL - if spectacular_settings.OAUTH2_REFRESH_URL: - flows[flow_type]["refreshUrl"] = spectacular_settings.OAUTH2_REFRESH_URL - scope_backend = get_scopes_backend() - flows[flow_type]["scopes"] = scope_backend.get_all_scopes() - - return {"type": "oauth2", "flows": flows}