web/flows: assign location from redirect challenge in request handler not render

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-27 09:43:00 +02:00
parent f50529cb5b
commit f601e04b38
1 changed files with 10 additions and 5 deletions

View File

@ -120,6 +120,16 @@ export class FlowExecutor extends LitElement implements StageHost {
.then((data) => { .then((data) => {
this.challenge = data; this.challenge = data;
this.postUpdate(); 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) => { .catch((e: Error | Response) => {
this.errorMessage(e); this.errorMessage(e);
@ -189,11 +199,6 @@ export class FlowExecutor extends LitElement implements StageHost {
} }
switch (this.challenge.type) { switch (this.challenge.type) {
case ChallengeChoices.Redirect: 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`<ak-empty-state ?loading=${true} header=${t`Loading`}> return html`<ak-empty-state ?loading=${true} header=${t`Loading`}>
</ak-empty-state>`; </ak-empty-state>`;
case ChallengeChoices.Shell: case ChallengeChoices.Shell: