From 548b1ead2f853939846e2f337bd183e6d2d2c6d9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 20 Feb 2021 20:28:57 +0100 Subject: [PATCH] flows: challenge error response in challenge format --- authentik/flows/challenge.py | 1 + authentik/flows/stage.py | 15 ++++++++++++--- authentik/stages/identification/stage.py | 1 - 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/authentik/flows/challenge.py b/authentik/flows/challenge.py index f19859749b..bca48deb64 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 22a3162d20..9f794f20ae 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 2da6aa1025..a10e78c32d 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