diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index 5d48a2365..fe6fb5129 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -26,6 +26,10 @@ class FieldTypes(models.TextChoices): # Simple text field TEXT = "text", _("Text: Simple Text input") + # Simple text field + TEXT_READ_ONLY = "text_read_only", _( + "Text (read-only): Simple Text input, but cannot be edited." + ) # Same as text, but has autocomplete for password managers USERNAME = ( "username", @@ -80,8 +84,6 @@ class Prompt(SerializerModel): kwargs = { "required": self.required, } - if default: - kwargs["initial"] = default if self.type == FieldTypes.EMAIL: field_class = EmailField @@ -105,6 +107,8 @@ class Prompt(SerializerModel): if self.type == FieldTypes.SEPARATOR: kwargs["required"] = False kwargs["label"] = "" + if default: + kwargs["initial"] = default return field_class(**kwargs) def save(self, *args, **kwargs): diff --git a/authentik/stages/prompt/stage.py b/authentik/stages/prompt/stage.py index 8365b0245..5ff8ac7e5 100644 --- a/authentik/stages/prompt/stage.py +++ b/authentik/stages/prompt/stage.py @@ -97,10 +97,10 @@ class PromptChallengeResponse(ChallengeResponse): # Check if we have any static or hidden fields, and ensure they # still have the same value static_hidden_fields: QuerySet[Prompt] = self.stage.fields.filter( - type__in=[FieldTypes.HIDDEN, FieldTypes.STATIC] + type__in=[FieldTypes.HIDDEN, FieldTypes.STATIC, FieldTypes.TEXT_READ_ONLY] ) for static_hidden in static_hidden_fields: - attrs[static_hidden.field_key] = static_hidden.placeholder + attrs[static_hidden.field_key] = self.fields[static_hidden.field_key].initial # Check if we have two password fields, and make sure they are the same password_fields: QuerySet[Prompt] = self.stage.fields.filter(type=FieldTypes.PASSWORD) diff --git a/schema.yml b/schema.yml index 117cf649a..ed2124ce5 100644 --- a/schema.yml +++ b/schema.yml @@ -17634,6 +17634,7 @@ paths: - separator - static - text + - text_read_only - username tags: - stages @@ -28374,6 +28375,7 @@ components: PromptTypeEnum: enum: - text + - text_read_only - username - email - password @@ -30728,4 +30730,3 @@ components: servers: - url: /api/v3/ - url: /api/v2beta/ - diff --git a/web/src/flows/stages/prompt/PromptStage.ts b/web/src/flows/stages/prompt/PromptStage.ts index b1f19ac24..3151c2aef 100644 --- a/web/src/flows/stages/prompt/PromptStage.ts +++ b/web/src/flows/stages/prompt/PromptStage.ts @@ -42,6 +42,13 @@ export class PromptStage extends BaseStage`; + case PromptTypeEnum.TextReadOnly: + return ``; case PromptTypeEnum.Username: return ` { > ${t`Text: Simple Text input`} +