flows: challenge error response in challenge format

This commit is contained in:
Jens Langhammer 2021-02-20 20:28:57 +01:00
parent 33f67140f2
commit 548b1ead2f
3 changed files with 13 additions and 4 deletions

View file

@ -19,6 +19,7 @@ class ChallengeTypes(Enum):
native = "native"
shell = "shell"
redirect = "redirect"
error = "error"
class Challenge(Serializer):

View file

@ -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
)

View file

@ -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