From f601e04b386f62fcbe4f8a19340dcda2ecea82f9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 27 Aug 2021 09:43:00 +0200 Subject: [PATCH] web/flows: assign location from redirect challenge in request handler not render Signed-off-by: Jens Langhammer --- web/src/flows/FlowExecutor.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/src/flows/FlowExecutor.ts b/web/src/flows/FlowExecutor.ts index b05dbc283..f24864b99 100644 --- a/web/src/flows/FlowExecutor.ts +++ b/web/src/flows/FlowExecutor.ts @@ -120,6 +120,16 @@ export class FlowExecutor extends LitElement implements StageHost { .then((data) => { this.challenge = data; this.postUpdate(); + // Assign the location as soon as we get the challenge and *not* in the render function + // as the render function might be called multiple times, which will navigate multiple + // times and can invalidate oauth codes + if (this.challenge.type === ChallengeChoices.Redirect) { + console.debug( + "authentik/flows: redirecting to url from server", + (this.challenge as RedirectChallenge).to, + ); + window.location.assign((this.challenge as RedirectChallenge).to); + } }) .catch((e: Error | Response) => { this.errorMessage(e); @@ -189,11 +199,6 @@ export class FlowExecutor extends LitElement implements StageHost { } switch (this.challenge.type) { case ChallengeChoices.Redirect: - console.debug( - "authentik/flows: redirecting to url from server", - (this.challenge as RedirectChallenge).to, - ); - window.location.assign((this.challenge as RedirectChallenge).to); return html` `; case ChallengeChoices.Shell: