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 <jens@goauthentik.io>

* update strings

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-05-05 23:24:43 +03:00 committed by GitHub
parent 5ca8eefa8b
commit 95a679ab3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 875 additions and 1058 deletions

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View File

@ -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`<ak-stage-redirect
.host=${this as StageHost}
.challenge=${this.challenge}
>
</ak-stage-redirect>`;
}
return html`<ak-empty-state ?loading=${true} header=${t`Loading`}>
</ak-empty-state>`;
return html`<ak-stage-redirect
.host=${this as StageHost}
.challenge=${this.challenge}
?promptUser=${this.inspectorOpen}
>
</ak-stage-redirect>`;
case ChallengeChoices.Shell:
return html`${unsafeHTML((this.challenge as ShellChallenge).body)}`;
case ChallengeChoices.Native:

View File

@ -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<RedirectChallenge, FlowChallengeResponseRequest> {
@property({ type: Boolean })
promptUser = false;
@state()
startedRedirect = false;
static get styles(): CSSResult[] {
return [
PFBase,
@ -39,12 +45,46 @@ export class RedirectStage extends BaseStage<RedirectChallenge, FlowChallengeRes
return this.challenge.to;
}
firstUpdated(): void {
if (this.promptUser) {
return;
}
console.debug(
"authentik/stages/redirect: redirecting to url from server",
this.challenge.to,
);
window.location.assign(this.challenge.to);
this.startedRedirect = true;
}
renderLoading(): TemplateResult {
const url = new URL(this.challenge.to);
// If the protocol isn't http or https assume a custom protocol, that has an OS-level
// handler, which the browser will show a popup for.
// As this wouldn't really be a redirect, show a message that the page can be closed
// and try to close it ourselves
if (!url.protocol.startsWith("http")) {
setTimeout(() => {
window.close();
}, 500);
return html`<ak-empty-state
icon="fas fa-check"
header=${t`You may close this page now.`}
>
</ak-empty-state>`;
}
return html`<ak-empty-state ?loading=${true} header=${t`Loading`}> </ak-empty-state>`;
}
render(): TemplateResult {
if (this.startedRedirect || !this.promptUser) {
return this.renderLoading();
}
return html`<header class="pf-c-login__main-header">
<h1 class="pf-c-title pf-m-3xl">${t`Redirect`}</h1>
</header>
<div class="pf-c-login__main-body">
<form method="POST" class="pf-c-form">
<form class="pf-c-form">
<div class="pf-c-form__group">
<p>${t`You're about to be redirect to the following URL.`}</p>
<code>${this.renderURL()}</code>
@ -54,6 +94,9 @@ export class RedirectStage extends BaseStage<RedirectChallenge, FlowChallengeRes
type="submit"
class="pf-c-button pf-m-primary pf-m-block"
href=${this.challenge.to}
@click=${() => {
this.startedRedirect = true;
}}
>
${t`Follow redirect`}
</a>

View File

@ -49,7 +49,9 @@ export class AuthenticatorDuoStage extends BaseStage<
).stagesAuthenticatorDuoEnrollmentStatusCreate({
stageUuid: this.challenge?.stageUuid || "",
});
console.debug(`authentik/flows/duo: Enrollment status: ${status.duoResponse}`);
console.debug(
`authentik/stages/authenticator_duo: Enrollment status: ${status.duoResponse}`,
);
switch (status.duoResponse) {
case DuoResponseEnum.Success:
this.host?.submit({});

View File

@ -900,6 +900,7 @@ msgstr "Zurück"
msgid "Backends"
msgstr "Backends"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "Hintergrund"
@ -3183,7 +3184,6 @@ msgstr "HTTPS wird nicht korrekt erkannt"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3684,7 +3684,6 @@ msgstr "Server laden"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3705,6 +3704,7 @@ msgstr "Server laden"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8036,6 +8036,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr "Sie können nur Anbieter auswählen, die zum Typ des Outposts passen."
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "Sie werden gleich zur folgenden URL weitergeleitet"

View File

@ -889,6 +889,7 @@ msgstr "Back"
msgid "Backends"
msgstr "Backends"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "Background"
@ -3225,7 +3226,6 @@ msgstr "HTTPS is not detected correctly"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3742,7 +3742,6 @@ msgstr "Load servers"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3763,6 +3762,7 @@ msgstr "Load servers"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8211,6 +8211,10 @@ msgstr "You can close this tab now."
msgid "You can only select providers that match the type of the outpost."
msgstr "You can only select providers that match the type of the outpost."
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr "You may close this page now."
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "You're about to be redirect to the following URL."

View File

@ -878,6 +878,7 @@ msgstr ""
msgid "Backends"
msgstr "Backends"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "Fondo"
@ -3159,7 +3160,6 @@ msgstr "HTTPS no se detecta correctamente"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3660,7 +3660,6 @@ msgstr "Cargar servidores"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3681,6 +3680,7 @@ msgstr "Cargar servidores"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8012,6 +8012,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr "Solo puede seleccionar proveedores que coincidan con el tipo de puesto avanzado."
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "Estás a punto de ser redirigido a la siguiente URL."

View File

@ -883,6 +883,7 @@ msgstr "Retour"
msgid "Backends"
msgstr "Backends"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "Arrière-plan"
@ -3162,7 +3163,6 @@ msgstr "HTTP n'est pas détecté correctement"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3661,7 +3661,6 @@ msgstr "Charger les serveurs"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3682,6 +3681,7 @@ msgstr "Charger les serveurs"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8001,6 +8001,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr "Vous pouvez uniquement sélectionner des fournisseurs qui correspondent au type d'avant-poste."
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "Vous allez être redirigé vers l'URL suivante."

View File

@ -882,6 +882,7 @@ msgstr "Wstecz"
msgid "Backends"
msgstr "back-end"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "Tło"
@ -3165,7 +3166,6 @@ msgstr "HTTPS nie jest poprawnie wykrywany"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3668,7 +3668,6 @@ msgstr "Załaduj serwery"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3689,6 +3688,7 @@ msgstr "Załaduj serwery"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8024,6 +8024,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr "Możesz wybrać tylko tych dostawców, którzy pasują do typu placówki."
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "Wkrótce nastąpi przekierowanie do następującego adresu URL."

View File

@ -881,6 +881,7 @@ msgstr ""
msgid "Backends"
msgstr ""
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr ""
@ -3211,7 +3212,6 @@ msgstr ""
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3721,7 +3721,6 @@ msgstr ""
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3742,6 +3741,7 @@ msgstr ""
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8159,6 +8159,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr ""

View File

@ -878,6 +878,7 @@ msgstr ""
msgid "Backends"
msgstr "Arka uçlar"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "Arkaplan"
@ -3159,7 +3160,6 @@ msgstr "HTTPS doğru algılanmadı"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3660,7 +3660,6 @@ msgstr "Sunucuları yükle"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3681,6 +3680,7 @@ msgstr "Sunucuları yükle"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8012,6 +8012,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr "Yalnızca üssün türüne uyan sağlayıcıları seçebilirsiniz."
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "Aşağıdaki URL'ye yönlendirmek üzeresiniz."

File diff suppressed because it is too large Load Diff

View File

@ -884,6 +884,7 @@ msgstr "返回"
msgid "Backends"
msgstr "后端"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "背景"
@ -3167,7 +3168,6 @@ msgstr "未正确检测到 HTTPS"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3668,7 +3668,6 @@ msgstr "加载服务器"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3689,6 +3688,7 @@ msgstr "加载服务器"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8022,6 +8022,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr "您只能选择与 Outpost 类型匹配的提供商。"
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "您将被重定向到以下 URL。"

View File

@ -884,6 +884,7 @@ msgstr "返回"
msgid "Backends"
msgstr "后端"
#: src/admin/flows/FlowForm.ts
#: src/admin/flows/FlowForm.ts
msgid "Background"
msgstr "背景"
@ -3167,7 +3168,6 @@ msgstr "未正确检测到 HTTPS"
#: src/admin/applications/ApplicationForm.ts
#: src/admin/applications/ApplicationForm.ts
#: src/admin/flows/FlowForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/oauth/OAuthSourceForm.ts
#: src/admin/sources/plex/PlexSourceForm.ts
@ -3668,7 +3668,6 @@ msgstr "加载服务器"
#: src/admin/events/EventViewPage.ts
#: src/elements/table/Table.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowExecutor.ts
#: src/flow/FlowInspector.ts
#: src/flow/providers/oauth2/DeviceCode.ts
#: src/flow/providers/oauth2/DeviceCodeFinish.ts
@ -3689,6 +3688,7 @@ msgstr "加载服务器"
#: src/flow/stages/identification/IdentificationStage.ts
#: src/flow/stages/password/PasswordStage.ts
#: src/flow/stages/prompt/PromptStage.ts
#: src/flow/stages/RedirectStage.ts
#: src/flow/stages/user_login/UserLoginStage.ts
#: src/user/LibraryPage.ts
#: src/user/user-settings/details/stages/prompt/PromptStage.ts
@ -8022,6 +8022,10 @@ msgstr ""
msgid "You can only select providers that match the type of the outpost."
msgstr "您只能选择与 Outpost 类型匹配的提供商。"
#: src/flow/stages/RedirectStage.ts
msgid "You may close this page now."
msgstr ""
#: src/flow/stages/RedirectStage.ts
msgid "You're about to be redirect to the following URL."
msgstr "您将被重定向到以下 URL。"