From 572b8d87b51a636df282e37955a141a3ff46f92e Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 13 Jun 2021 12:59:28 +0200 Subject: [PATCH] api: fix import error Signed-off-by: Jens Langhammer --- authentik/api/apps.py | 23 +++++++++++++++++++++++ authentik/api/authentication.py | 16 ---------------- schema.yml | 11 ++++------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/authentik/api/apps.py b/authentik/api/apps.py index 8ae859a54..86e817eea 100644 --- a/authentik/api/apps.py +++ b/authentik/api/apps.py @@ -10,3 +10,26 @@ class AuthentikAPIConfig(AppConfig): label = "authentik_api" mountpoint = "api/" verbose_name = "authentik API" + + def ready(self) -> None: + from drf_spectacular.extensions import OpenApiAuthenticationExtension + + from authentik.api.authentication import TokenAuthentication + + # Class is defined here as it needs to be created early enough that drf-spectacular will + # find it, but also won't cause any import issues + + # pylint: disable=unused-variable + class TokenSchema(OpenApiAuthenticationExtension): + """Auth schema""" + + target_class = TokenAuthentication + name = "authentik" + + def get_security_definition(self, auto_schema): + """Auth schema""" + return { + "type": "apiKey", + "in": "header", + "name": "Authorization", + } diff --git a/authentik/api/authentication.py b/authentik/api/authentication.py index c3a760141..1d38fc9e5 100644 --- a/authentik/api/authentication.py +++ b/authentik/api/authentication.py @@ -3,7 +3,6 @@ from base64 import b64decode from binascii import Error from typing import Any, Optional, Union -from drf_spectacular.authentication import OpenApiAuthenticationExtension from rest_framework.authentication import BaseAuthentication, get_authorization_header from rest_framework.exceptions import AuthenticationFailed from rest_framework.request import Request @@ -56,18 +55,3 @@ class TokenAuthentication(BaseAuthentication): return None return (token.user, None) # pragma: no cover - - -class TokenSchema(OpenApiAuthenticationExtension): - """Auth schema""" - - target_class = TokenAuthentication - name = "authentik" - - def get_security_definition(self, auto_schema): - """Auth schema""" - return { - "type": "apiKey", - "in": "header", - "name": "Authorization", - } diff --git a/schema.yml b/schema.yml index 9e6d2f9a5..1366e80e5 100644 --- a/schema.yml +++ b/schema.yml @@ -1,7 +1,7 @@ openapi: 3.0.3 info: title: authentik - version: 2021.6.1-rc4 + version: 2021.6.1-rc5 description: Making authentication simple. contact: email: hello@beryju.org @@ -2717,14 +2717,10 @@ paths: name: is_active schema: type: boolean - title: Active - description: Designates whether this user should be treated as active. Unselect - this instead of deleting accounts. - in: query name: is_superuser schema: - type: string - format: uuid + type: boolean - in: query name: name schema: @@ -3041,7 +3037,7 @@ paths: - in: query name: has_key schema: - type: string + type: boolean description: Only return certificate-key pairs with keys - in: query name: name @@ -26137,6 +26133,7 @@ components: forward_auth_mode: type: boolean readOnly: true + deprecated: true required: - external_host - forward_auth_mode