diff --git a/authentik/root/settings.py b/authentik/root/settings.py index e5abff0df..2ef7e65c9 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -176,6 +176,7 @@ SPECTACULAR_SETTINGS = { "FlowDesignationEnum": "authentik.flows.models.FlowDesignation", "PolicyEngineMode": "authentik.policies.models.PolicyEngineMode", "ProxyMode": "authentik.providers.proxy.models.ProxyMode", + "PromptTypeEnum": "authentik.stages.prompt.models.FieldTypes", }, "ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE": False, "POSTPROCESSING_HOOKS": [ diff --git a/authentik/stages/prompt/stage.py b/authentik/stages/prompt/stage.py index 5a84c0996..f26bc2872 100644 --- a/authentik/stages/prompt/stage.py +++ b/authentik/stages/prompt/stage.py @@ -8,7 +8,7 @@ from django.http import HttpRequest, HttpResponse from django.http.request import QueryDict from django.utils.translation import gettext_lazy as _ from guardian.shortcuts import get_anonymous_user -from rest_framework.fields import BooleanField, CharField, IntegerField +from rest_framework.fields import BooleanField, CharField, ChoiceField, IntegerField from rest_framework.serializers import ValidationError from structlog.stdlib import get_logger @@ -31,7 +31,7 @@ class StagePromptSerializer(PassiveSerializer): field_key = CharField() label = CharField(allow_blank=True) - type = CharField() + type = ChoiceField(choices=FieldTypes.choices) required = BooleanField() placeholder = CharField(allow_blank=True) order = IntegerField() diff --git a/schema.yml b/schema.yml index b8d9f21a3..ed42da4a5 100644 --- a/schema.yml +++ b/schema.yml @@ -29646,7 +29646,7 @@ components: label: type: string type: - type: string + $ref: '#/components/schemas/PromptTypeEnum' required: type: boolean placeholder: diff --git a/web/src/flows/stages/prompt/PromptStage.ts b/web/src/flows/stages/prompt/PromptStage.ts index 8b9016a63..65be0c733 100644 --- a/web/src/flows/stages/prompt/PromptStage.ts +++ b/web/src/flows/stages/prompt/PromptStage.ts @@ -13,7 +13,12 @@ import PFLogin from "@patternfly/patternfly/components/Login/login.css"; import PFTitle from "@patternfly/patternfly/components/Title/title.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; -import { PromptChallenge, PromptChallengeResponseRequest, StagePrompt } from "@goauthentik/api"; +import { + PromptChallenge, + PromptChallengeResponseRequest, + PromptTypeEnum, + StagePrompt, +} from "@goauthentik/api"; import "../../../elements/Divider"; import "../../../elements/EmptyState"; @@ -28,7 +33,7 @@ export class PromptStage extends BaseStage`; - case "username": + case PromptTypeEnum.Username: return ``; - case "email": + case PromptTypeEnum.Email: return ``; - case "password": + case PromptTypeEnum.Password: return ``; - case "number": + case PromptTypeEnum.Number: return ``; - case "date": + case PromptTypeEnum.Date: return ``; - case "date-time": + case PromptTypeEnum.DateTime: return ``; - case "separator": + case PromptTypeEnum.Separator: return `${prompt.placeholder}`; - case "hidden": + case PromptTypeEnum.Hidden: return ``; - case "static": + case PromptTypeEnum.Static: return `

${prompt.placeholder}

`; } return ""; @@ -114,7 +119,7 @@ export class PromptStage extends BaseStage ${this.challenge.fields.map((prompt) => { // Checkbox is rendered differently - if (prompt.type === "checkbox") { + if (prompt.type === PromptTypeEnum.Checkbox) { return html`