diff --git a/web/src/api/Config.ts b/web/src/api/Config.ts index 7a47ed0d4f..488e758bf2 100644 --- a/web/src/api/Config.ts +++ b/web/src/api/Config.ts @@ -1,4 +1,4 @@ -import { Configuration, Middleware, ResponseContext } from "authentik-api"; +import { Config, Configuration, Middleware, ResponseContext, RootApi } from "authentik-api"; import { getCookie } from "../utils"; import { API_DRAWER_MIDDLEWARE } from "../elements/notifications/APIDrawer"; import { MessageMiddleware } from "../elements/messages/Middleware"; @@ -12,6 +12,14 @@ export class LoggingMiddleware implements Middleware { } +let globalConfigPromise: Promise; +export function config(): Promise { + if (!globalConfigPromise) { + globalConfigPromise = new RootApi(DEFAULT_CONFIG).rootConfigList(); + } + return globalConfigPromise; +} + export const DEFAULT_CONFIG = new Configuration({ basePath: "/api/v2beta", headers: { diff --git a/web/src/api/Sentry.ts b/web/src/api/Sentry.ts index a4f6558664..ef7f9f2e41 100644 --- a/web/src/api/Sentry.ts +++ b/web/src/api/Sentry.ts @@ -2,12 +2,12 @@ import * as Sentry from "@sentry/browser"; import { Integrations } from "@sentry/tracing"; import { VERSION } from "../constants"; import { SentryIgnoredError } from "../common/errors"; -import { Config, RootApi } from "authentik-api"; import { me } from "./Users"; -import { DEFAULT_CONFIG } from "./Config"; +import { config } from "./Config"; +import { Config } from "authentik-api"; export function configureSentry(): Promise { - return new RootApi(DEFAULT_CONFIG).rootConfigList().then((config) => { + return config().then((config) => { if (config.errorReportingEnabled) { Sentry.init({ dsn: "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8", diff --git a/web/src/api/Users.ts b/web/src/api/Users.ts index db0ceafad5..a0201c7cc5 100644 --- a/web/src/api/Users.ts +++ b/web/src/api/Users.ts @@ -1,10 +1,10 @@ import { CoreApi, SessionUser } from "authentik-api"; import { DEFAULT_CONFIG } from "./Config"; -let _globalMePromise: Promise; +let globalMePromise: Promise; export function me(): Promise { - if (!_globalMePromise) { - _globalMePromise = new CoreApi(DEFAULT_CONFIG).coreUsersMe().catch((ex) => { + if (!globalMePromise) { + globalMePromise = new CoreApi(DEFAULT_CONFIG).coreUsersMe().catch((ex) => { const defaultUser: SessionUser = { user: { username: "", @@ -17,5 +17,5 @@ export function me(): Promise { return defaultUser; }); } - return _globalMePromise; + return globalMePromise; } diff --git a/web/src/constants.ts b/web/src/constants.ts index 9028f6cca0..675df79b5d 100644 --- a/web/src/constants.ts +++ b/web/src/constants.ts @@ -9,5 +9,5 @@ export const EVENT_REFRESH = "ak-refresh"; export const EVENT_NOTIFICATION_TOGGLE = "ak-notification-toggle"; export const EVENT_SIDEBAR_TOGGLE = "ak-sidebar-toggle"; export const EVENT_API_DRAWER_REFRESH = "ak-api-drawer-refresh"; -export const TITLE_SUFFIX = "authentik"; +export const TITLE_DEFAULT = "authentik"; export const ROUTE_SEPARATOR = ";"; diff --git a/web/src/elements/PageHeader.ts b/web/src/elements/PageHeader.ts index 87cc379b63..7be03f7281 100644 --- a/web/src/elements/PageHeader.ts +++ b/web/src/elements/PageHeader.ts @@ -4,7 +4,8 @@ import PFContent from "@patternfly/patternfly/components/Content/content.css"; import AKGlobal from "../authentik.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; -import { EVENT_SIDEBAR_TOGGLE, TITLE_SUFFIX } from "../constants"; +import { EVENT_SIDEBAR_TOGGLE, TITLE_DEFAULT } from "../constants"; +import { config } from "../api/Config"; @customElement("ak-page-header") export class PageHeader extends LitElement { @@ -17,11 +18,13 @@ export class PageHeader extends LitElement { @property() set header(value: string) { - if (value !== "") { - document.title = `${value} - ${TITLE_SUFFIX}`; - } else { - document.title = TITLE_SUFFIX; - } + config().then(config => { + if (value !== "") { + document.title = `${value} - ${config.brandingTitle}`; + } else { + document.title = config.brandingTitle || TITLE_DEFAULT; + } + }); this._header = value; } diff --git a/web/src/flows/FlowExecutor.ts b/web/src/flows/FlowExecutor.ts index a907e58b97..2e44b01e71 100644 --- a/web/src/flows/FlowExecutor.ts +++ b/web/src/flows/FlowExecutor.ts @@ -37,12 +37,12 @@ import { WebAuthnAuthenticatorRegisterChallenge } from "./stages/authenticator_w import { CaptchaChallenge } from "./stages/captcha/CaptchaStage"; import { StageHost } from "./stages/base"; import { Challenge, ChallengeTypeEnum, Config, FlowsApi } from "authentik-api"; -import { DEFAULT_CONFIG } from "../api/Config"; +import { config, DEFAULT_CONFIG } from "../api/Config"; import { ifDefined } from "lit-html/directives/if-defined"; import { until } from "lit-html/directives/until"; import { AccessDeniedChallenge } from "./access_denied/FlowAccessDenied"; import { PFSize } from "../elements/Spinner"; -import { TITLE_SUFFIX } from "../constants"; +import { TITLE_DEFAULT } from "../constants"; import { configureSentry } from "../api/Sentry"; @customElement("ak-flow-executor") @@ -99,11 +99,13 @@ export class FlowExecutor extends LitElement implements StageHost { } private postUpdate(): void { - if (this.challenge?.title) { - document.title = `${this.challenge.title} - ${TITLE_SUFFIX}`; - } else { - document.title = TITLE_SUFFIX; - } + config().then(config => { + if (this.challenge?.title) { + document.title = `${this.challenge.title} - ${config.brandingTitle}`; + } else { + document.title = config.brandingTitle || TITLE_DEFAULT; + } + }); } submit(formData?: T): Promise { diff --git a/web/src/locales/en.po b/web/src/locales/en.po index c80b262ed2..aaa1f86a9e 100644 --- a/web/src/locales/en.po +++ b/web/src/locales/en.po @@ -1665,8 +1665,8 @@ msgid "Library" msgstr "Library" #: src/elements/table/Table.ts:120 -#: src/flows/FlowExecutor.ts:165 -#: src/flows/FlowExecutor.ts:211 +#: src/flows/FlowExecutor.ts:167 +#: src/flows/FlowExecutor.ts:213 #: src/flows/access_denied/FlowAccessDenied.ts:27 #: src/flows/stages/authenticator_static/AuthenticatorStaticStage.ts:43 #: src/flows/stages/authenticator_totp/AuthenticatorTOTPStage.ts:33 @@ -2321,7 +2321,7 @@ msgstr "Post binding" msgid "Post binding (auto-submit)" msgstr "Post binding (auto-submit)" -#: src/flows/FlowExecutor.ts:253 +#: src/flows/FlowExecutor.ts:255 msgid "Powered by authentik" msgstr "Powered by authentik" @@ -2575,7 +2575,7 @@ msgstr "Retry Task" msgid "Retry authentication" msgstr "Retry authentication" -#: src/flows/FlowExecutor.ts:143 +#: src/flows/FlowExecutor.ts:145 msgid "Return" msgstr "Return" @@ -2823,7 +2823,7 @@ msgstr "Skip path regex" msgid "Slug" msgstr "Slug" -#: src/flows/FlowExecutor.ts:136 +#: src/flows/FlowExecutor.ts:138 msgid "Something went wrong! Please try again later." msgstr "Something went wrong! Please try again later." @@ -3863,7 +3863,7 @@ msgstr "When selected, incoming assertion's Signatures will be validated against msgid "When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged." msgstr "When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged." -#: src/flows/FlowExecutor.ts:132 +#: src/flows/FlowExecutor.ts:134 msgid "Whoops!" msgstr "Whoops!" diff --git a/web/src/locales/pseudo-LOCALE.po b/web/src/locales/pseudo-LOCALE.po index a08efecdee..a346554c30 100644 --- a/web/src/locales/pseudo-LOCALE.po +++ b/web/src/locales/pseudo-LOCALE.po @@ -1657,8 +1657,8 @@ msgid "Library" msgstr "" #: src/elements/table/Table.ts:120 -#: src/flows/FlowExecutor.ts:165 -#: src/flows/FlowExecutor.ts:211 +#: src/flows/FlowExecutor.ts:167 +#: src/flows/FlowExecutor.ts:213 #: src/flows/access_denied/FlowAccessDenied.ts:27 #: src/flows/stages/authenticator_static/AuthenticatorStaticStage.ts:43 #: src/flows/stages/authenticator_totp/AuthenticatorTOTPStage.ts:33 @@ -2313,7 +2313,7 @@ msgstr "" msgid "Post binding (auto-submit)" msgstr "" -#: src/flows/FlowExecutor.ts:253 +#: src/flows/FlowExecutor.ts:255 msgid "Powered by authentik" msgstr "" @@ -2567,7 +2567,7 @@ msgstr "" msgid "Retry authentication" msgstr "" -#: src/flows/FlowExecutor.ts:143 +#: src/flows/FlowExecutor.ts:145 msgid "Return" msgstr "" @@ -2815,7 +2815,7 @@ msgstr "" msgid "Slug" msgstr "" -#: src/flows/FlowExecutor.ts:136 +#: src/flows/FlowExecutor.ts:138 msgid "Something went wrong! Please try again later." msgstr "" @@ -3851,7 +3851,7 @@ msgstr "" msgid "When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged." msgstr "" -#: src/flows/FlowExecutor.ts:132 +#: src/flows/FlowExecutor.ts:134 msgid "Whoops!" msgstr ""