diff --git a/authentik/flows/challenge.py b/authentik/flows/challenge.py index f19859749..bca48deb6 100644 --- a/authentik/flows/challenge.py +++ b/authentik/flows/challenge.py @@ -19,6 +19,7 @@ class ChallengeTypes(Enum): native = "native" shell = "shell" redirect = "redirect" + error = "error" class Challenge(Serializer): diff --git a/authentik/flows/stage.py b/authentik/flows/stage.py index 22a3162d2..9f794f20a 100644 --- a/authentik/flows/stage.py +++ b/authentik/flows/stage.py @@ -1,6 +1,6 @@ """authentik stage Base view""" from collections import namedtuple -from typing import Any, Type +from typing import Any from django.http import HttpRequest from django.http.request import QueryDict @@ -10,7 +10,7 @@ from django.views.generic import TemplateView from authentik.flows.challenge import ( Challenge, - ChallengeResponse, + ChallengeResponse, ChallengeTypes, HttpChallengeResponse, ) from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER @@ -85,4 +85,13 @@ class ChallengeStageView(StageView): def challenge_invalid(self, challenge: ChallengeResponse) -> HttpResponse: """Callback when the challenge has the incorrect format""" - return JsonResponse(challenge.errors) + challenge_response = Challenge(data={ + "type": ChallengeTypes.error, + "args": { + "errors": challenge.errors + } + }) + challenge_response.is_valid() + return HttpChallengeResponse( + challenge_response + ) diff --git a/authentik/stages/identification/stage.py b/authentik/stages/identification/stage.py index 2da6aa102..a10e78c32 100644 --- a/authentik/stages/identification/stage.py +++ b/authentik/stages/identification/stage.py @@ -1,7 +1,6 @@ """Identification stage logic""" from typing import Optional, Union -from django.contrib import messages from django.db.models import Q from django.http import HttpResponse from django.urls import reverse