authentik.enterprise.stages.authenticator_endpoint_gdtc.stage

 1from typing import Any
 2
 3from django.http import HttpRequest, HttpResponse
 4from django.urls import reverse
 5from django.utils.translation import gettext_lazy as _
 6
 7from authentik.enterprise.stages.authenticator_endpoint_gdtc.views.dtc import (
 8    PLAN_CONTEXT_METHOD_ARGS_ENDPOINTS,
 9)
10from authentik.flows.challenge import (
11    Challenge,
12    ChallengeResponse,
13    FrameChallenge,
14    FrameChallengeResponse,
15    HttpChallengeResponse,
16)
17from authentik.flows.stage import ChallengeStageView
18from authentik.stages.password.stage import PLAN_CONTEXT_METHOD_ARGS
19
20
21class AuthenticatorEndpointStageView(ChallengeStageView):
22    """Endpoint stage"""
23
24    response_class = FrameChallengeResponse
25
26    def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
27        method_args = self.executor.plan.context.get(PLAN_CONTEXT_METHOD_ARGS, {})
28        if method_args.get(PLAN_CONTEXT_METHOD_ARGS_ENDPOINTS):
29            return self.executor.stage_ok()
30        return super().dispatch(request, *args, **kwargs)
31
32    def get_challenge(self, *args, **kwargs) -> Challenge:
33        return FrameChallenge(
34            data={
35                "component": "xak-flow-frame",
36                "url": self.request.build_absolute_uri(
37                    reverse("authentik_stages_authenticator_endpoint_gdtc:chrome")
38                ),
39                "loading_overlay": True,
40                "loading_text": _("Verifying your browser..."),
41            }
42        )
43
44    def challenge_valid(self, response: ChallengeResponse) -> HttpResponse:
45        challenge = self._get_challenge()
46        challenge.is_valid()
47        return HttpChallengeResponse(challenge)
class AuthenticatorEndpointStageView(authentik.flows.stage.ChallengeStageView):
22class AuthenticatorEndpointStageView(ChallengeStageView):
23    """Endpoint stage"""
24
25    response_class = FrameChallengeResponse
26
27    def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
28        method_args = self.executor.plan.context.get(PLAN_CONTEXT_METHOD_ARGS, {})
29        if method_args.get(PLAN_CONTEXT_METHOD_ARGS_ENDPOINTS):
30            return self.executor.stage_ok()
31        return super().dispatch(request, *args, **kwargs)
32
33    def get_challenge(self, *args, **kwargs) -> Challenge:
34        return FrameChallenge(
35            data={
36                "component": "xak-flow-frame",
37                "url": self.request.build_absolute_uri(
38                    reverse("authentik_stages_authenticator_endpoint_gdtc:chrome")
39                ),
40                "loading_overlay": True,
41                "loading_text": _("Verifying your browser..."),
42            }
43        )
44
45    def challenge_valid(self, response: ChallengeResponse) -> HttpResponse:
46        challenge = self._get_challenge()
47        challenge.is_valid()
48        return HttpChallengeResponse(challenge)

Endpoint stage

def dispatch( self, request: django.http.request.HttpRequest, *args: Any, **kwargs: Any) -> django.http.response.HttpResponse:
27    def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
28        method_args = self.executor.plan.context.get(PLAN_CONTEXT_METHOD_ARGS, {})
29        if method_args.get(PLAN_CONTEXT_METHOD_ARGS_ENDPOINTS):
30            return self.executor.stage_ok()
31        return super().dispatch(request, *args, **kwargs)
def get_challenge(self, *args, **kwargs) -> authentik.flows.challenge.Challenge:
33    def get_challenge(self, *args, **kwargs) -> Challenge:
34        return FrameChallenge(
35            data={
36                "component": "xak-flow-frame",
37                "url": self.request.build_absolute_uri(
38                    reverse("authentik_stages_authenticator_endpoint_gdtc:chrome")
39                ),
40                "loading_overlay": True,
41                "loading_text": _("Verifying your browser..."),
42            }
43        )

Return the challenge that the client should solve

def challenge_valid( self, response: authentik.flows.challenge.ChallengeResponse) -> django.http.response.HttpResponse:
45    def challenge_valid(self, response: ChallengeResponse) -> HttpResponse:
46        challenge = self._get_challenge()
47        challenge.is_valid()
48        return HttpChallengeResponse(challenge)

Callback when the challenge has the correct format