Skip to content

Build your personal knowledge base with Trilium Notes

feat(oauth): derive issuer icon from base URL favicon

Elian Doranc62670cf29b7
diff --git a/apps/client/src/widgets/type_widgets/options/password.tsx b/apps/client/src/widgets/type_widgets/options/password.tsx
index 0649689786..e75452aaeb 100644
--- a/apps/client/src/widgets/type_widgets/options/password.tsx
+++ b/apps/client/src/widgets/type_widgets/options/password.tsx
@@ -359,9 +359,7 @@ function OAuthProviderRows({ status }: { status?: OAuthStatus }) {
<>
<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" /> }
+ <OAuthProviderIcon src={status?.issuerIcon} />
<span>{displayName}</span>
</span>
</OptionsRow>
@@ -374,6 +372,21 @@ function OAuthProviderRows({ status }: { status?: OAuthStatus }) {
);
}
+/**
+ * Provider icon for the OAuth status card. Renders the configured/derived issuer icon, falling back
+ * to a neutral key glyph when no icon is available or the image fails to load (e.g. a derived
+ * favicon URL that the issuer doesn't actually serve).
+ */
+function OAuthProviderIcon({ src }: { src?: string }) {
+ const [ failed, setFailed ] = useState(false);
+
+ if (!src || failed) {
+ return <span className="bx bx-key oauth-provider-icon" />;
+ }
+
+ return <img className="oauth-provider-icon" src={src} alt="" onError={() => setFailed(true)} />;
+}
+
/**
* 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.
diff --git a/apps/server/src/assets/images/google-logo.svg b/apps/server/src/assets/images/google-logo.svg
deleted file mode 100644
index c69cd1e7f9..0000000000
--- a/apps/server/src/assets/images/google-logo.svg
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<svg viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg">
- <path d="M17.64 9.2c0-.637-.057-1.251-.164-1.84H9v3.481h4.844c-.209 1.125-.843 2.078-1.796 2.716v2.259h2.908c1.702-1.567 2.684-3.875 2.684-6.615z" fill="#4285f4"/>
- <path d="M9 18c2.43 0 4.467-.806 5.956-2.184l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332C2.438 15.983 5.482 18 9 18z" fill="#34a853"/>
- <path d="M3.964 10.71c-.18-.54-.282-1.117-.282-1.71s.102-1.17.282-1.71V4.958H.957C.347 6.173 0 7.548 0 9s.348 2.827.957 4.042l3.007-2.332z" fill="#fbbc05"/>
- <path d="M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0 5.482 0 2.438 2.017.957 4.958L3.964 7.29C4.672 5.163 6.656 3.58 9 3.58z" fill="#ea4335"/>
-</svg>
\ No newline at end of file
diff --git a/apps/server/src/assets/views/login.ejs b/apps/server/src/assets/views/login.ejs
index 91e764ba21..2740f34854 100644
--- a/apps/server/src/assets/views/login.ejs
+++ b/apps/server/src/assets/views/login.ejs
@@ -25,7 +25,9 @@
<% if (ssoEnabled) { %>
<a href="/authenticate" class="google-login-btn">
- <img src="<%= ssoIssuerIcon.length === 0 ? assetPathFragment + '/images/google-logo.svg' : ssoIssuerIcon %>" alt="<%= ssoIssuerName %>">
+ <% if (ssoIssuerIcon.length > 0) { %>
+ <img src="<%= ssoIssuerIcon %>" alt="<%= ssoIssuerName %>" onerror="this.remove()">
+ <% } %>
<%= t("login.sign_in_with_sso", { ssoIssuerName: ssoIssuerName }) %>
</a>
<% } else { %>
diff --git a/apps/server/src/services/open_id.spec.ts b/apps/server/src/services/open_id.spec.ts
index 749ab5b4d3..4b4dce28ba 100644
--- a/apps/server/src/services/open_id.spec.ts
+++ b/apps/server/src/services/open_id.spec.ts
@@ -73,6 +73,23 @@ describe("open_id", () => {
expect(openID.getSSOIssuerIcon()).toBe("icon.png");
});
+ it("derives the issuer icon from the base URL favicon when none is configured", () => {
+ setOauthConfig(true);
+ mfa.oauthIssuerIcon = "";
+
+ // Falls back to the issuer's favicon.
+ mfa.oauthIssuerBaseUrl = "https://issuer.example.com";
+ expect(openID.getSSOIssuerIcon()).toBe("https://issuer.example.com/favicon.ico");
+
+ // Trailing slashes / extra path segments resolve against the origin root.
+ mfa.oauthIssuerBaseUrl = "https://accounts.google.com/";
+ expect(openID.getSSOIssuerIcon()).toBe("https://accounts.google.com/favicon.ico");
+
+ // No (or invalid) base URL → no icon, leaving the UI to use its glyph fallback.
+ mfa.oauthIssuerBaseUrl = "";
+ expect(openID.getSSOIssuerIcon()).toBe("");
+ });
+
it("isUserSaved and getOAuthStatus read user_data", () => {
cls.init(() => {
sql.transactional(() => {
diff --git a/apps/server/src/services/open_id.ts b/apps/server/src/services/open_id.ts
index bec6f6f6e0..b8d14578fb 100644
--- a/apps/server/src/services/open_id.ts
+++ b/apps/server/src/services/open_id.ts
@@ -110,7 +110,26 @@ function getSSOIssuerName() {
}
function getSSOIssuerIcon() {
- return config.MultiFactorAuthentication.oauthIssuerIcon;
+ const configuredIcon = config.MultiFactorAuthentication.oauthIssuerIcon;
+ if (configuredIcon) {
+ return configuredIcon;
+ }
+
+ // Fall back to the issuer's favicon so any OIDC provider gets a sensible default icon
+ // without requiring explicit configuration.
+ return deriveFaviconUrl(config.MultiFactorAuthentication.oauthIssuerBaseUrl);
+}
+
+function deriveFaviconUrl(baseUrl: string) {
+ if (!baseUrl) {
+ return "";
+ }
+
+ try {
+ return new URL("/favicon.ico", baseUrl).toString();
+ } catch {
+ return "";
+ }
}
function generateOAuthConfig() {