Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 70cdc10

Browse files
authored
Merge pull request #2198 from TriliumNext/oidc
Support custom oidc server
2 parents 17c2ae1 + bffb476 commit 70cdc10

7 files changed

Lines changed: 43 additions & 7 deletions

File tree

apps/server/src/assets/config-sample.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,15 @@ oauthClientId=
5555
# Set the client secret for OAuth/OpenID authentication
5656
# This is the secret of the client that will be used to verify the user's identity
5757
oauthClientSecret=
58+
59+
# Set the issuer base URL for OAuth/OpenID authentication
60+
# This is the base URL of the service that will be used to verify the user's identity
61+
oauthIssuerBaseUrl=
62+
63+
# Set the issuer name for OAuth/OpenID authentication
64+
# This is the name of the service that will be used to verify the user's identity
65+
oauthIssuerName=
66+
67+
# Set the issuer icon for OAuth/OpenID authentication
68+
# This is the icon of the service that will be used to verify the user's identity
69+
oauthIssuerIcon=

apps/server/src/assets/translations/cn/server.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"password": "密码",
104104
"remember-me": "记住我",
105105
"button": "登录",
106-
"sign_in_with_google": "使用 Google 登录"
106+
"sign_in_with_sso": "使用 {{ ssoIssuerName }} 登录"
107107
},
108108
"set_password": {
109109
"title": "设置密码",

apps/server/src/assets/translations/en/server.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"password": "Password",
113113
"remember-me": "Remember me",
114114
"button": "Login",
115-
"sign_in_with_google": "Sign in with Google"
115+
"sign_in_with_sso": "Sign in with {{ ssoIssuerName }}"
116116
},
117117
"set_password": {
118118
"title": "Set Password",

apps/server/src/assets/views/login.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
<% if (ssoEnabled) { %>
2828
<a href="/authenticate" class="google-login-btn">
29-
<img src="<%= assetPath %>/images/google-logo.svg" alt="Google logo">
30-
<%= t("login.sign_in_with_google") %>
29+
<img src="<%= ssoIssuerIcon.length === 0 ? assetPathFragment + '/images/google-logo.svg' : ssoIssuerIcon %>" alt="<%= ssoIssuerName %>">
30+
<%= t("login.sign_in_with_sso", { ssoIssuerName: ssoIssuerName }) %>
3131
</a>
3232
<% } else { %>
3333
<form action="login" method="POST">

apps/server/src/routes/login.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function loginPage(req: Request, res: Response) {
1919
wrongTotp: false,
2020
totpEnabled: totp.isTotpEnabled(),
2121
ssoEnabled: openID.isOpenIDEnabled(),
22+
ssoIssuerName: openID.getSSOIssuerName(),
23+
ssoIssuerIcon: openID.getSSOIssuerIcon(),
2224
assetPath: assetPath,
2325
assetPathFragment: assetUrlFragment,
2426
appPath: appPath,

apps/server/src/services/config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export interface TriliumConfig {
4646
oauthBaseUrl: string;
4747
oauthClientId: string;
4848
oauthClientSecret: string;
49+
oauthIssuerBaseUrl: string;
50+
oauthIssuerName: string;
51+
oauthIssuerIcon: string;
4952
};
5053
}
5154

@@ -123,7 +126,16 @@ const config: TriliumConfig = {
123126
process.env.TRILIUM_OAUTH_CLIENT_ID || iniConfig?.MultiFactorAuthentication?.oauthClientId || "",
124127

125128
oauthClientSecret:
126-
process.env.TRILIUM_OAUTH_CLIENT_SECRET || iniConfig?.MultiFactorAuthentication?.oauthClientSecret || ""
129+
process.env.TRILIUM_OAUTH_CLIENT_SECRET || iniConfig?.MultiFactorAuthentication?.oauthClientSecret || "",
130+
131+
oauthIssuerBaseUrl:
132+
process.env.TRILIUM_OAUTH_ISSUER_BASE_URL || iniConfig?.MultiFactorAuthentication?.oauthIssuerBaseUrl || "https://accounts.google.com",
133+
134+
oauthIssuerName:
135+
process.env.TRILIUM_OAUTH_ISSUER_NAME || iniConfig?.MultiFactorAuthentication?.oauthIssuerName || "Google",
136+
137+
oauthIssuerIcon:
138+
process.env.TRILIUM_OAUTH_ISSUER_ICON || iniConfig?.MultiFactorAuthentication?.oauthIssuerIcon || ""
127139
}
128140
};
129141

apps/server/src/services/open_id.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import config from "./config.js";
88

99

1010
function checkOpenIDConfig() {
11-
let missingVars: string[] = []
11+
const missingVars: string[] = []
1212
if (config.MultiFactorAuthentication.oauthBaseUrl === "") {
1313
missingVars.push("oauthBaseUrl");
1414
}
@@ -89,6 +89,14 @@ function isTokenValid(req: Request, res: Response, next: NextFunction) {
8989
}
9090
}
9191

92+
function getSSOIssuerName() {
93+
return config.MultiFactorAuthentication.oauthIssuerName;
94+
}
95+
96+
function getSSOIssuerIcon() {
97+
return config.MultiFactorAuthentication.oauthIssuerIcon;
98+
}
99+
92100
function generateOAuthConfig() {
93101
const authRoutes = {
94102
callback: "/callback",
@@ -105,7 +113,7 @@ function generateOAuthConfig() {
105113
auth0Logout: false,
106114
baseURL: config.MultiFactorAuthentication.oauthBaseUrl,
107115
clientID: config.MultiFactorAuthentication.oauthClientId,
108-
issuerBaseURL: "https://accounts.google.com",
116+
issuerBaseURL: config.MultiFactorAuthentication.oauthIssuerBaseUrl,
109117
secret: config.MultiFactorAuthentication.oauthClientSecret,
110118
clientSecret: config.MultiFactorAuthentication.oauthClientSecret,
111119
authorizationParams: {
@@ -147,6 +155,8 @@ function generateOAuthConfig() {
147155
export default {
148156
generateOAuthConfig,
149157
getOAuthStatus,
158+
getSSOIssuerName,
159+
getSSOIssuerIcon,
150160
isOpenIDEnabled,
151161
clearSavedUser,
152162
isTokenValid,

0 commit comments

Comments
 (0)