Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(oauth): show the configured provider on the OpenID settings card
Elian Doran9705600ed67f
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex b6271a60e2..99af817639 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1747,6 +1747,9 @@"oauth_how_to_enable": "How to enable","oauth_server_config_hint": "Add the following to your config.ini file and restart the application:","oauth_server_env_hint": "Or set the following environment variables:",+ "oauth_provider": "Provider",+ "oauth_provider_url": "Issuer URL",+ "oauth_provider_unknown": "Unknown provider","oauth_user_account": "Account name","oauth_user_email": "Email address","oauth_user_not_logged_in": "Not logged in!",diff --git a/apps/client/src/widgets/type_widgets/options/password.css b/apps/client/src/widgets/type_widgets/options/password.cssindex ece9b07e9b..2615a1a109 100644--- a/apps/client/src/widgets/type_widgets/options/password.css+++ b/apps/client/src/widgets/type_widgets/options/password.css@@ -15,3 +15,18 @@.oauth-status-badge.not-configured {--color: var(--muted-text-color, #888);}++/* Provider row: the issuer icon (or a fallback key glyph) sitting just before its display name. */+.oauth-provider {+ display: inline-flex;+ align-items: center;+ gap: 8px;+}++.oauth-provider-icon {+ width: 1.2em;+ height: 1.2em;+ object-fit: contain;+ font-size: 1.2em;+ line-height: 1;+}diff --git a/apps/client/src/widgets/type_widgets/options/password.tsx b/apps/client/src/widgets/type_widgets/options/password.tsxindex aee5be6c2f..5b649ad932 100644--- a/apps/client/src/widgets/type_widgets/options/password.tsx+++ b/apps/client/src/widgets/type_widgets/options/password.tsx@@ -299,6 +299,7 @@ function OAuthStatusCard({ status, refreshStatus }: { status?: OAuthStatus, refr</>) : enrolled ? (<>+ <OAuthProviderRows status={status} /><OptionsRow name="oauth-user-account" label={t("multi_factor_authentication.oauth_user_account")}><span>{status?.name ?? t("multi_factor_authentication.oauth_user_not_logged_in")}</span></OptionsRow>@@ -317,6 +318,7 @@ function OAuthStatusCard({ status, refreshStatus }: { status?: OAuthStatus, refr</>) : (<>+ <OAuthProviderRows status={status} /><Admonition type="note">{t("multi_factor_authentication.oauth_not_enrolled_hint")}</Admonition><OptionsRowWithButton@@ -332,6 +334,51 @@ function OAuthStatusCard({ status, refreshStatus }: { status?: OAuthStatus, refr);}+/**+ * Identifies the configured OAuth provider: its icon and display name, plus the issuer URL. Shown+ * whenever OAuth is configured so the owner can confirm which server they'll be redirected to.+ */+function OAuthProviderRows({ status }: { status?: OAuthStatus }) {+ const displayName = oauthProviderDisplayName(status);+ return (+ <>+ <OptionsRow name="oauth-provider" label={t("multi_factor_authentication.oauth_provider")}>+ <span className="oauth-provider">+ { status?.issuerIcon+ ? <img className="oauth-provider-icon" src={status.issuerIcon} alt="" />+ : <span className="bx bx-key oauth-provider-icon" /> }+ <span>{displayName}</span>+ </span>+ </OptionsRow>+ { status?.issuerUrl && (+ <OptionsRow name="oauth-provider-url" label={t("multi_factor_authentication.oauth_provider_url")}>+ <span>{status.issuerUrl}</span>+ </OptionsRow>+ )}+ </>+ );+}++/**+ * Resolves the provider's display name: the configured issuer name, falling back to the host of the+ * issuer URL (e.g. "auth.example.com"), and finally to a generic label when neither is available.+ */+function oauthProviderDisplayName(status?: OAuthStatus) {+ if (status?.issuerName) {+ return status.issuerName;+ }++ if (status?.issuerUrl) {+ try {+ return new URL(status.issuerUrl).host;+ } catch {+ return status.issuerUrl;+ }+ }++ return t("multi_factor_authentication.oauth_provider_unknown");+}+/*** Collapsible "How to enable" hint for OAuth, mirroring the security page's ServerConfigHint. Lists* the config.ini section and the equivalent environment variables the server reads — OAuth has nodiff --git a/apps/server/src/services/open_id.spec.ts b/apps/server/src/services/open_id.spec.tsindex 988c2dbf09..749ab5b4d3 100644--- a/apps/server/src/services/open_id.spec.ts+++ b/apps/server/src/services/open_id.spec.ts@@ -91,6 +91,14 @@ describe("open_id", () => {expect(status.email).toBe("[email protected]");});+ it("getOAuthStatus surfaces the configured issuer details", () => {+ setOauthConfig(true);+ const status = openID.getOAuthStatus();+ expect(status.issuerName).toBe("Acme");+ expect(status.issuerUrl).toBe("https://issuer.example.com");+ expect(status.issuerIcon).toBe("icon.png");+ });+it("clearSavedUser empties user_data", () => {const result = cls.init(() => openID.clearSavedUser());expect(result.success).toBe(true);diff --git a/apps/server/src/services/open_id.ts b/apps/server/src/services/open_id.tsindex c3c2ea2e34..bec6f6f6e0 100644--- a/apps/server/src/services/open_id.ts+++ b/apps/server/src/services/open_id.ts@@ -71,7 +71,10 @@ function getOAuthStatus() {email: getUserEmail(),enabled: isOpenIDEnabled(),enrolled: openIDEncryption.isSubjectIdentifierSaved(),- missingVars: checkOpenIDConfig()+ missingVars: checkOpenIDConfig(),+ issuerName: getSSOIssuerName(),+ issuerUrl: config.MultiFactorAuthentication.oauthIssuerBaseUrl,+ issuerIcon: getSSOIssuerIcon()};}diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex a9b9583b6a..6bae31446e 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -171,6 +171,12 @@ export interface OAuthStatus {name?: string;email?: string;missingVars?: string[];+ /** The configured provider's display name (`oauthIssuerName`); empty when unset. */+ issuerName?: string;+ /** The configured provider's issuer base URL (`oauthIssuerBaseUrl`). */+ issuerUrl?: string;+ /** The configured provider's icon URL (`oauthIssuerIcon`); empty when unset. */+ issuerIcon?: string;}// Interface for the Ollama model response