From 95a679ab3be40c8f208fecd1297fb7dd8417b749 Mon Sep 17 00:00:00 2001 From: Jens L Date: Fri, 5 May 2023 23:24:43 +0300 Subject: [PATCH] web/flows: rework redirect logic (#5498) * web/flows: rework redirect logic always use redirect stage, remove special logic from flow executor show better message when redirect target URL isn't http or https (show notice to close the page) Signed-off-by: Jens Langhammer * update strings Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- locale/en/LC_MESSAGES/django.po | 4 +- web/src/flow/FlowExecutor.ts | 28 +- web/src/flow/stages/RedirectStage.ts | 47 +- .../AuthenticatorDuoStage.ts | 4 +- web/src/locales/de.po | 8 +- web/src/locales/en.po | 8 +- web/src/locales/es.po | 8 +- web/src/locales/fr_FR.po | 8 +- web/src/locales/pl.po | 8 +- web/src/locales/pseudo-LOCALE.po | 8 +- web/src/locales/tr.po | 8 +- web/src/locales/zh-Hans.po | 1778 +++++++---------- web/src/locales/zh-Hant.po | 8 +- web/src/locales/zh_TW.po | 8 +- 14 files changed, 875 insertions(+), 1058 deletions(-) diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 9b853b089..d2f6a012c 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-05-03 14:41+0000\n" +"POT-Creation-Date: 2023-05-05 20:11+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -65,7 +65,7 @@ msgstr "" msgid "authentik Export - %(date)s" msgstr "" -#: authentik/blueprints/v1/tasks.py:146 authentik/crypto/tasks.py:93 +#: authentik/blueprints/v1/tasks.py:149 authentik/crypto/tasks.py:93 #, python-format msgid "Successfully imported %(count)d files." msgstr "" diff --git a/web/src/flow/FlowExecutor.ts b/web/src/flow/FlowExecutor.ts index b22711edc..d581245c4 100644 --- a/web/src/flow/FlowExecutor.ts +++ b/web/src/flow/FlowExecutor.ts @@ -37,7 +37,6 @@ import { FlowErrorChallenge, FlowsApi, LayoutEnum, - RedirectChallenge, ResponseError, ShellChallenge, UiThemeEnum, @@ -52,18 +51,6 @@ export class FlowExecutor extends Interface implements StageHost { @property({ attribute: false }) set challenge(value: ChallengeTypes | undefined) { this._challenge = value; - // 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 - // Also only auto-redirect when the inspector is open, so that a user can inspect the - // redirect in the inspector - if (value?.type === ChallengeChoices.Redirect && !this.inspectorOpen) { - console.debug( - "authentik/flows: redirecting to url from server", - (value as RedirectChallenge).to, - ); - window.location.assign((value as RedirectChallenge).to); - } if (value?.flowInfo?.title) { document.title = `${value.flowInfo?.title} - ${this.tenant?.brandingTitle}`; } else { @@ -407,15 +394,12 @@ export class FlowExecutor extends Interface implements StageHost { } switch (this.challenge.type) { case ChallengeChoices.Redirect: - if (this.inspectorOpen) { - return html` - `; - } - return html` - `; + return html` + `; case ChallengeChoices.Shell: return html`${unsafeHTML((this.challenge as ShellChallenge).body)}`; case ChallengeChoices.Native: diff --git a/web/src/flow/stages/RedirectStage.ts b/web/src/flow/stages/RedirectStage.ts index fda5db764..f542edfc4 100644 --- a/web/src/flow/stages/RedirectStage.ts +++ b/web/src/flow/stages/RedirectStage.ts @@ -3,7 +3,7 @@ import { BaseStage } from "@goauthentik/flow/stages/base"; import { t } from "@lingui/macro"; import { CSSResult, TemplateResult, css, html } from "lit"; -import { customElement } from "lit/decorators.js"; +import { customElement, property, state } from "lit/decorators.js"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; import PFForm from "@patternfly/patternfly/components/Form/form.css"; @@ -16,6 +16,12 @@ import { FlowChallengeResponseRequest, RedirectChallenge } from "@goauthentik/ap @customElement("ak-stage-redirect") export class RedirectStage extends BaseStage { + @property({ type: Boolean }) + promptUser = false; + + @state() + startedRedirect = false; + static get styles(): CSSResult[] { return [ PFBase, @@ -39,12 +45,46 @@ export class RedirectStage extends BaseStage { + window.close(); + }, 500); + return html` + `; + } + return html` `; + } + render(): TemplateResult { + if (this.startedRedirect || !this.promptUser) { + return this.renderLoading(); + } return html`