2021-02-17 22:52:49 +00:00
|
|
|
import { gettext } from "django";
|
2021-02-21 21:01:35 +00:00
|
|
|
import { LitElement, html, customElement, property, TemplateResult, CSSResult, css } from "lit-element";
|
2021-03-16 21:02:58 +00:00
|
|
|
|
2021-03-17 12:23:33 +00:00
|
|
|
import PFLogin from "@patternfly/patternfly/components/Login/login.css";
|
2021-03-17 16:11:39 +00:00
|
|
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
|
|
|
import PFTitle from "@patternfly/patternfly/components/Title/title.css";
|
2021-03-21 16:36:51 +00:00
|
|
|
import PFBackgroundImage from "@patternfly/patternfly/components/BackgroundImage/background-image.css";
|
|
|
|
import PFList from "@patternfly/patternfly/components/List/list.css";
|
|
|
|
import AKGlobal from "../authentik.css";
|
2021-03-16 21:02:58 +00:00
|
|
|
|
2021-02-17 22:52:49 +00:00
|
|
|
import { unsafeHTML } from "lit-html/directives/unsafe-html";
|
2021-03-08 10:14:00 +00:00
|
|
|
import "./stages/authenticator_static/AuthenticatorStaticStage";
|
|
|
|
import "./stages/authenticator_totp/AuthenticatorTOTPStage";
|
|
|
|
import "./stages/authenticator_validate/AuthenticatorValidateStage";
|
|
|
|
import "./stages/authenticator_webauthn/WebAuthnAuthenticatorRegisterStage";
|
|
|
|
import "./stages/autosubmit/AutosubmitStage";
|
|
|
|
import "./stages/captcha/CaptchaStage";
|
|
|
|
import "./stages/consent/ConsentStage";
|
|
|
|
import "./stages/email/EmailStage";
|
|
|
|
import "./stages/identification/IdentificationStage";
|
|
|
|
import "./stages/password/PasswordStage";
|
|
|
|
import "./stages/prompt/PromptStage";
|
|
|
|
import { ShellChallenge, RedirectChallenge } from "../api/Flows";
|
|
|
|
import { IdentificationChallenge } from "./stages/identification/IdentificationStage";
|
|
|
|
import { PasswordChallenge } from "./stages/password/PasswordStage";
|
|
|
|
import { ConsentChallenge } from "./stages/consent/ConsentStage";
|
|
|
|
import { EmailChallenge } from "./stages/email/EmailStage";
|
|
|
|
import { AutosubmitChallenge } from "./stages/autosubmit/AutosubmitStage";
|
|
|
|
import { PromptChallenge } from "./stages/prompt/PromptStage";
|
|
|
|
import { AuthenticatorTOTPChallenge } from "./stages/authenticator_totp/AuthenticatorTOTPStage";
|
|
|
|
import { AuthenticatorStaticChallenge } from "./stages/authenticator_static/AuthenticatorStaticStage";
|
|
|
|
import { AuthenticatorValidateStageChallenge } from "./stages/authenticator_validate/AuthenticatorValidateStage";
|
|
|
|
import { WebAuthnAuthenticatorRegisterChallenge } from "./stages/authenticator_webauthn/WebAuthnAuthenticatorRegisterStage";
|
|
|
|
import { CaptchaChallenge } from "./stages/captcha/CaptchaStage";
|
|
|
|
import { SpinnerSize } from "../elements/Spinner";
|
|
|
|
import { StageHost } from "./stages/base";
|
2021-03-21 16:36:51 +00:00
|
|
|
import { Challenge, ChallengeTypeEnum, Config, FlowsApi, RootApi } from "authentik-api";
|
2021-03-08 10:14:00 +00:00
|
|
|
import { DEFAULT_CONFIG } from "../api/Config";
|
2021-03-21 16:36:51 +00:00
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import { until } from "lit-html/directives/until";
|
2021-03-22 13:39:51 +00:00
|
|
|
import { TITLE_SUFFIX } from "../elements/router/RouterOutlet";
|
2020-11-20 21:08:00 +00:00
|
|
|
|
2021-02-17 22:52:49 +00:00
|
|
|
@customElement("ak-flow-executor")
|
2021-02-23 12:50:47 +00:00
|
|
|
export class FlowExecutor extends LitElement implements StageHost {
|
2021-03-21 16:36:51 +00:00
|
|
|
|
|
|
|
flowSlug: string;
|
2020-11-20 21:08:00 +00:00
|
|
|
|
2021-02-17 22:52:49 +00:00
|
|
|
@property({attribute: false})
|
2021-02-20 22:19:27 +00:00
|
|
|
challenge?: Challenge;
|
2020-10-16 14:36:18 +00:00
|
|
|
|
2021-02-21 21:01:35 +00:00
|
|
|
@property({type: Boolean})
|
2021-02-21 21:01:58 +00:00
|
|
|
loading = false;
|
2021-02-21 21:01:35 +00:00
|
|
|
|
2021-03-21 16:36:51 +00:00
|
|
|
@property({ attribute: false })
|
|
|
|
config?: Config;
|
|
|
|
|
2021-02-21 21:01:35 +00:00
|
|
|
static get styles(): CSSResult[] {
|
2021-03-21 16:36:51 +00:00
|
|
|
return [PFBase, PFLogin, PFTitle, PFList, PFBackgroundImage, AKGlobal].concat(css`
|
2021-02-21 21:01:35 +00:00
|
|
|
.ak-loading {
|
|
|
|
display: flex;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
position: absolute;
|
2021-03-21 14:01:48 +00:00
|
|
|
background-color: var(--pf-global--BackgroundColor--dark-transparent-100);
|
|
|
|
z-index: 1;
|
2021-02-21 21:01:35 +00:00
|
|
|
}
|
|
|
|
.ak-hidden {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
:host {
|
|
|
|
position: relative;
|
|
|
|
}
|
2021-03-17 16:11:39 +00:00
|
|
|
.ak-exception {
|
|
|
|
font-family: monospace;
|
|
|
|
overflow-x: scroll;
|
|
|
|
}
|
2021-02-21 21:01:35 +00:00
|
|
|
`);
|
2020-10-16 14:36:18 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 19:49:58 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.addEventListener("ak-flow-submit", () => {
|
2021-02-17 22:52:49 +00:00
|
|
|
this.submit();
|
2021-02-17 19:49:58 +00:00
|
|
|
});
|
2021-03-22 12:44:17 +00:00
|
|
|
this.flowSlug = window.location.pathname.split("/")[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
setBackground(url: string): void {
|
|
|
|
this.shadowRoot?.querySelectorAll<HTMLDivElement>(".pf-c-background-image").forEach((bg) => {
|
|
|
|
bg.style.setProperty("--ak-flow-background", `url('${url}')`);
|
|
|
|
});
|
2021-02-17 19:49:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 13:39:51 +00:00
|
|
|
private postUpdate(): void {
|
|
|
|
if (this.challenge?.background) {
|
|
|
|
this.setBackground(this.challenge.background);
|
|
|
|
}
|
|
|
|
if (this.challenge?.title) {
|
|
|
|
document.title = `${this.challenge.title} - ${TITLE_SUFFIX}`;
|
|
|
|
} else {
|
|
|
|
document.title = TITLE_SUFFIX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 10:14:00 +00:00
|
|
|
submit<T>(formData?: T): Promise<void> {
|
2021-02-21 21:01:35 +00:00
|
|
|
this.loading = true;
|
2021-03-08 10:14:00 +00:00
|
|
|
return new FlowsApi(DEFAULT_CONFIG).flowsExecutorSolveRaw({
|
|
|
|
flowSlug: this.flowSlug,
|
|
|
|
data: formData || {},
|
|
|
|
}).then((challengeRaw) => {
|
|
|
|
return challengeRaw.raw.json();
|
|
|
|
}).then((data) => {
|
|
|
|
this.challenge = data;
|
2021-03-22 13:39:51 +00:00
|
|
|
this.postUpdate();
|
2021-03-08 10:14:00 +00:00
|
|
|
}).catch((e) => {
|
|
|
|
this.errorMessage(e);
|
|
|
|
}).finally(() => {
|
|
|
|
this.loading = false;
|
|
|
|
});
|
2021-02-17 22:52:49 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 08:15:41 +00:00
|
|
|
firstUpdated(): void {
|
2021-03-21 16:36:51 +00:00
|
|
|
new RootApi(DEFAULT_CONFIG).rootConfigList().then((config) => {
|
|
|
|
this.config = config;
|
|
|
|
});
|
2021-02-21 21:01:35 +00:00
|
|
|
this.loading = true;
|
2021-03-08 10:14:00 +00:00
|
|
|
new FlowsApi(DEFAULT_CONFIG).flowsExecutorGetRaw({
|
|
|
|
flowSlug: this.flowSlug
|
|
|
|
}).then((challengeRaw) => {
|
|
|
|
return challengeRaw.raw.json();
|
|
|
|
}).then((challenge) => {
|
|
|
|
this.challenge = challenge as Challenge;
|
2021-03-22 13:39:51 +00:00
|
|
|
this.postUpdate();
|
2021-02-20 22:19:27 +00:00
|
|
|
}).catch((e) => {
|
|
|
|
// Catch JSON or Update errors
|
|
|
|
this.errorMessage(e);
|
2021-02-21 21:01:35 +00:00
|
|
|
}).finally(() => {
|
|
|
|
this.loading = false;
|
2020-10-16 14:36:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:15:41 +00:00
|
|
|
errorMessage(error: string): void {
|
2021-02-20 22:19:27 +00:00
|
|
|
this.challenge = <ShellChallenge>{
|
2021-03-08 10:14:00 +00:00
|
|
|
type: ChallengeTypeEnum.Shell,
|
2021-03-17 16:11:39 +00:00
|
|
|
body: `<header class="pf-c-login__main-header">
|
|
|
|
<h1 class="pf-c-title pf-m-3xl">
|
|
|
|
${gettext("Whoops!")}
|
|
|
|
</h1>
|
|
|
|
</header>
|
|
|
|
<div class="pf-c-login__main-body">
|
|
|
|
<h3>${gettext("Something went wrong! Please try again later.")}</h3>
|
|
|
|
<pre class="ak-exception">${error}</pre>
|
|
|
|
</div>`
|
2021-02-20 22:19:27 +00:00
|
|
|
};
|
2020-10-26 09:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 21:01:35 +00:00
|
|
|
renderLoading(): TemplateResult {
|
|
|
|
return html`<div class="ak-loading">
|
|
|
|
<ak-spinner size=${SpinnerSize.XLarge}></ak-spinner>
|
2020-11-21 19:48:49 +00:00
|
|
|
</div>`;
|
2020-10-16 14:36:18 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 21:01:35 +00:00
|
|
|
renderChallenge(): TemplateResult {
|
2021-02-20 22:19:27 +00:00
|
|
|
if (!this.challenge) {
|
2021-03-08 09:23:43 +00:00
|
|
|
return this.renderLoading();
|
2021-02-20 22:19:27 +00:00
|
|
|
}
|
2021-02-21 21:01:35 +00:00
|
|
|
switch (this.challenge.type) {
|
2021-03-08 10:14:00 +00:00
|
|
|
case ChallengeTypeEnum.Redirect:
|
2021-02-21 21:01:35 +00:00
|
|
|
console.debug(`authentik/flows: redirecting to ${(this.challenge as RedirectChallenge).to}`);
|
|
|
|
window.location.assign((this.challenge as RedirectChallenge).to);
|
2021-03-08 09:23:43 +00:00
|
|
|
return this.renderLoading();
|
2021-03-08 10:14:00 +00:00
|
|
|
case ChallengeTypeEnum.Shell:
|
2021-02-21 21:01:35 +00:00
|
|
|
return html`${unsafeHTML((this.challenge as ShellChallenge).body)}`;
|
2021-03-08 10:14:00 +00:00
|
|
|
case ChallengeTypeEnum.Native:
|
2021-02-21 21:01:35 +00:00
|
|
|
switch (this.challenge.component) {
|
|
|
|
case "ak-stage-identification":
|
|
|
|
return html`<ak-stage-identification .host=${this} .challenge=${this.challenge as IdentificationChallenge}></ak-stage-identification>`;
|
|
|
|
case "ak-stage-password":
|
|
|
|
return html`<ak-stage-password .host=${this} .challenge=${this.challenge as PasswordChallenge}></ak-stage-password>`;
|
2021-02-25 18:58:38 +00:00
|
|
|
case "ak-stage-captcha":
|
|
|
|
return html`<ak-stage-captcha .host=${this} .challenge=${this.challenge as CaptchaChallenge}></ak-stage-captcha>`;
|
2021-02-21 21:01:35 +00:00
|
|
|
case "ak-stage-consent":
|
|
|
|
return html`<ak-stage-consent .host=${this} .challenge=${this.challenge as ConsentChallenge}></ak-stage-consent>`;
|
|
|
|
case "ak-stage-email":
|
|
|
|
return html`<ak-stage-email .host=${this} .challenge=${this.challenge as EmailChallenge}></ak-stage-email>`;
|
|
|
|
case "ak-stage-autosubmit":
|
|
|
|
return html`<ak-stage-autosubmit .host=${this} .challenge=${this.challenge as AutosubmitChallenge}></ak-stage-autosubmit>`;
|
|
|
|
case "ak-stage-prompt":
|
|
|
|
return html`<ak-stage-prompt .host=${this} .challenge=${this.challenge as PromptChallenge}></ak-stage-prompt>`;
|
|
|
|
case "ak-stage-authenticator-totp":
|
|
|
|
return html`<ak-stage-authenticator-totp .host=${this} .challenge=${this.challenge as AuthenticatorTOTPChallenge}></ak-stage-authenticator-totp>`;
|
|
|
|
case "ak-stage-authenticator-static":
|
|
|
|
return html`<ak-stage-authenticator-static .host=${this} .challenge=${this.challenge as AuthenticatorStaticChallenge}></ak-stage-authenticator-static>`;
|
2021-02-23 12:50:47 +00:00
|
|
|
case "ak-stage-authenticator-webauthn":
|
|
|
|
return html`<ak-stage-authenticator-webauthn .host=${this} .challenge=${this.challenge as WebAuthnAuthenticatorRegisterChallenge}></ak-stage-authenticator-webauthn>`;
|
2021-02-23 22:43:13 +00:00
|
|
|
case "ak-stage-authenticator-validate":
|
|
|
|
return html`<ak-stage-authenticator-validate .host=${this} .challenge=${this.challenge as AuthenticatorValidateStageChallenge}></ak-stage-authenticator-validate>`;
|
2021-02-21 21:01:35 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.debug(`authentik/flows: unexpected data type ${this.challenge.type}`);
|
|
|
|
break;
|
2020-10-16 14:36:18 +00:00
|
|
|
}
|
2021-02-20 22:19:27 +00:00
|
|
|
return html``;
|
2020-10-16 14:36:18 +00:00
|
|
|
}
|
2021-02-21 21:01:35 +00:00
|
|
|
|
2021-03-21 16:36:51 +00:00
|
|
|
renderChallengeWrapper(): TemplateResult {
|
2021-02-21 21:01:35 +00:00
|
|
|
if (!this.challenge) {
|
|
|
|
return this.renderLoading();
|
|
|
|
}
|
|
|
|
return html`
|
|
|
|
${this.loading ? this.renderLoading() : html``}
|
|
|
|
${this.renderChallenge()}
|
|
|
|
`;
|
|
|
|
}
|
2021-03-21 16:36:51 +00:00
|
|
|
|
|
|
|
render(): TemplateResult {
|
|
|
|
return html`<div class="pf-c-background-image">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="pf-c-background-image__filter" width="0" height="0">
|
|
|
|
<filter id="image_overlay">
|
|
|
|
<feColorMatrix in="SourceGraphic" type="matrix" values="1.3 0 0 0 0 0 1.3 0 0 0 0 0 1.3 0 0 0 0 0 1 0" />
|
|
|
|
<feComponentTransfer color-interpolation-filters="sRGB" result="duotone">
|
|
|
|
<feFuncR type="table" tableValues="0.086274509803922 0.43921568627451"></feFuncR>
|
|
|
|
<feFuncG type="table" tableValues="0.086274509803922 0.43921568627451"></feFuncG>
|
|
|
|
<feFuncB type="table" tableValues="0.086274509803922 0.43921568627451"></feFuncB>
|
|
|
|
<feFuncA type="table" tableValues="0 1"></feFuncA>
|
|
|
|
</feComponentTransfer>
|
|
|
|
</filter>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
<ak-message-container></ak-message-container>
|
|
|
|
<div class="pf-c-login">
|
|
|
|
<div class="ak-login-container">
|
|
|
|
<header class="pf-c-login__header">
|
|
|
|
<div class="pf-c-brand ak-brand">
|
|
|
|
<img src="${ifDefined(this.config?.brandingLogo)}" alt="authentik icon" />
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div class="pf-c-login__main">
|
|
|
|
${this.renderChallengeWrapper()}
|
|
|
|
</div>
|
|
|
|
<footer class="pf-c-login__footer">
|
|
|
|
<p></p>
|
|
|
|
<ul class="pf-c-list pf-m-inline">
|
|
|
|
${until(this.config?.uiFooterLinks?.map((link) => {
|
|
|
|
return html`<li>
|
|
|
|
<a href="${link.href || ""}">${link.name}</a>
|
|
|
|
</li>`;
|
|
|
|
}))}
|
|
|
|
${this.config?.brandingTitle != "authentik" ? html`
|
|
|
|
<li><a href="https://goauthentik.io">${gettext("Powered by authentik")}</a></li>
|
|
|
|
` : html``}
|
|
|
|
</ul>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
2020-10-16 14:36:18 +00:00
|
|
|
}
|