From 716923e17a64a23ed1b95011e5107ed4008c5d53 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 24 May 2021 20:52:12 +0200 Subject: [PATCH] web/flows: update types Signed-off-by: Jens Langhammer --- authentik/stages/prompt/stage.py | 6 ++--- authentik/stages/prompt/tests.py | 10 ++++----- schema.yml | 22 +++++++++---------- web/src/flows/FlowExecutor.ts | 14 ++++++------ .../flows/access_denied/FlowAccessDenied.ts | 8 +++---- web/src/flows/sources/plex/PlexLoginInit.ts | 8 +++---- .../AuthenticatorDuoStage.ts | 8 +++---- .../AuthenticatorStaticStage.ts | 8 +++---- .../AuthenticatorTOTPStage.ts | 9 +++----- .../AuthenticatorValidateStage.ts | 16 +++++--------- .../AuthenticatorValidateStageCode.ts | 7 ++---- .../AuthenticatorValidateStageDuo.ts | 7 ++---- .../AuthenticatorValidateStageWebAuthn.ts | 13 +++++------ .../WebAuthnAuthenticatorRegisterStage.ts | 7 ++---- .../stages/autosubmit/AutosubmitStage.ts | 8 +++---- web/src/flows/stages/base.ts | 18 +++++++-------- web/src/flows/stages/captcha/CaptchaStage.ts | 9 +++----- web/src/flows/stages/consent/ConsentStage.ts | 9 +++----- web/src/flows/stages/dummy/DummyStage.ts | 9 +++----- web/src/flows/stages/email/EmailStage.ts | 9 +++----- .../identification/IdentificationStage.ts | 11 ++++------ .../flows/stages/password/PasswordStage.ts | 9 +++----- web/src/flows/stages/prompt/PromptStage.ts | 10 ++++----- 23 files changed, 93 insertions(+), 142 deletions(-) diff --git a/authentik/stages/prompt/stage.py b/authentik/stages/prompt/stage.py index c231ff696..e818a6c52 100644 --- a/authentik/stages/prompt/stage.py +++ b/authentik/stages/prompt/stage.py @@ -44,7 +44,7 @@ class PromptChallenge(Challenge): component = CharField(default="ak-stage-prompt") -class PromptResponseChallenge(ChallengeResponse): +class PromptChallengeResponse(ChallengeResponse): """Validate response, fields are dynamically created based on the stage""" @@ -159,7 +159,7 @@ class ListPolicyEngine(PolicyEngine): class PromptStageView(ChallengeStageView): """Prompt Stage, save form data in plan context.""" - response_class = PromptResponseChallenge + response_class = PromptChallengeResponse def get_challenge(self, *args, **kwargs) -> Challenge: fields = list(self.executor.current_stage.fields.all().order_by("order")) @@ -174,7 +174,7 @@ class PromptStageView(ChallengeStageView): def get_response_instance(self, data: QueryDict) -> ChallengeResponse: if not self.executor.plan: raise ValueError - return PromptResponseChallenge( + return PromptChallengeResponse( instance=None, data=data, stage=self.executor.current_stage, diff --git a/authentik/stages/prompt/tests.py b/authentik/stages/prompt/tests.py index 11d09ce02..4787ce3a6 100644 --- a/authentik/stages/prompt/tests.py +++ b/authentik/stages/prompt/tests.py @@ -13,7 +13,7 @@ from authentik.flows.planner import FlowPlan from authentik.flows.views import SESSION_KEY_PLAN from authentik.policies.expression.models import ExpressionPolicy from authentik.stages.prompt.models import FieldTypes, Prompt, PromptStage -from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT, PromptResponseChallenge +from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT, PromptChallengeResponse class TestPromptStage(TestCase): @@ -112,7 +112,7 @@ class TestPromptStage(TestCase): self.assertIn(prompt.label, force_str(response.content)) self.assertIn(prompt.placeholder, force_str(response.content)) - def test_valid_challenge_with_policy(self) -> PromptResponseChallenge: + def test_valid_challenge_with_policy(self) -> PromptChallengeResponse: """Test challenge_response validation""" plan = FlowPlan( flow_pk=self.flow.pk.hex, stages=[self.stage], markers=[StageMarker()] @@ -123,13 +123,13 @@ class TestPromptStage(TestCase): ) self.stage.validation_policies.set([expr_policy]) self.stage.save() - challenge_response = PromptResponseChallenge( + challenge_response = PromptChallengeResponse( None, stage=self.stage, plan=plan, data=self.prompt_data ) self.assertEqual(challenge_response.is_valid(), True) return challenge_response - def test_invalid_challenge(self) -> PromptResponseChallenge: + def test_invalid_challenge(self) -> PromptChallengeResponse: """Test challenge_response validation""" plan = FlowPlan( flow_pk=self.flow.pk.hex, stages=[self.stage], markers=[StageMarker()] @@ -140,7 +140,7 @@ class TestPromptStage(TestCase): ) self.stage.validation_policies.set([expr_policy]) self.stage.save() - challenge_response = PromptResponseChallenge( + challenge_response = PromptChallengeResponse( None, stage=self.stage, plan=plan, data=self.prompt_data ) self.assertEqual(challenge_response.is_valid(), False) diff --git a/schema.yml b/schema.yml index dd834649d..5b73f2570 100644 --- a/schema.yml +++ b/schema.yml @@ -16807,7 +16807,7 @@ components: - $ref: '#/components/schemas/IdentificationChallengeResponseRequest' - $ref: '#/components/schemas/PasswordChallengeResponseRequest' - $ref: '#/components/schemas/PlexAuthenticationChallengeResponseRequest' - - $ref: '#/components/schemas/PromptResponseChallengeRequest' + - $ref: '#/components/schemas/PromptChallengeResponseRequest' discriminator: propertyName: component mapping: @@ -16824,7 +16824,7 @@ components: ak-stage-identification: '#/components/schemas/IdentificationChallengeResponseRequest' ak-stage-password: '#/components/schemas/PasswordChallengeResponseRequest' ak-flow-sources-plex: '#/components/schemas/PlexAuthenticationChallengeResponseRequest' - ak-stage-prompt: '#/components/schemas/PromptResponseChallengeRequest' + ak-stage-prompt: '#/components/schemas/PromptChallengeResponseRequest' FlowDesignationEnum: enum: - authentication @@ -22995,6 +22995,15 @@ components: required: - fields - type + PromptChallengeResponseRequest: + type: object + description: |- + Validate response, fields are dynamically created based + on the stage + properties: + component: + type: string + default: ak-stage-prompt PromptRequest: type: object description: Prompt Serializer @@ -23024,15 +23033,6 @@ components: - field_key - label - type - PromptResponseChallengeRequest: - type: object - description: |- - Validate response, fields are dynamically created based - on the stage - properties: - component: - type: string - default: ak-stage-prompt PromptStage: type: object description: PromptStage Serializer diff --git a/web/src/flows/FlowExecutor.ts b/web/src/flows/FlowExecutor.ts index 6abe6a430..4688b833b 100644 --- a/web/src/flows/FlowExecutor.ts +++ b/web/src/flows/FlowExecutor.ts @@ -34,6 +34,7 @@ import { PFSize } from "../elements/Spinner"; import { TITLE_DEFAULT } from "../constants"; import { configureSentry } from "../api/Sentry"; import { ChallengeResponseRequest } from "authentik-api/dist/models/ChallengeResponseRequest"; +import { FlowChallengeResponseRequest } from "authentik-api/src"; @customElement("ak-flow-executor") @@ -77,9 +78,6 @@ export class FlowExecutor extends LitElement implements StageHost { constructor() { super(); - this.addEventListener("ak-flow-submit", () => { - this.submit(); - }); this.flowSlug = window.location.pathname.split("/")[3]; } @@ -100,12 +98,14 @@ export class FlowExecutor extends LitElement implements StageHost { } submit(payload: ChallengeResponseRequest): Promise { - payload.component = this.challenge.component; + // @ts-ignore + payload.component = this.challenge?.component; + console.log(payload); this.loading = true; return new FlowsApi(DEFAULT_CONFIG).flowsExecutorSolve({ flowSlug: this.flowSlug, query: window.location.search.substring(1), - challengeResponseRequest: payload, + flowChallengeResponseRequest: payload as FlowChallengeResponseRequest, }).then((data) => { this.challenge = data; this.postUpdate(); @@ -142,7 +142,7 @@ export class FlowExecutor extends LitElement implements StageHost { } errorMessage(error: string): void { - this.challenge = { + this.challenge = { type: ChallengeChoices.Shell, body: `