From 4762287d6184d6f629fdebe75d026da168cf1670 Mon Sep 17 00:00:00 2001 From: Jin <22962980+JYC333@users.noreply.github.com> Date: Wed, 26 Mar 2025 01:58:54 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Remove=20redundant=20fun?= =?UTF-8?q?c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 2 +- src/services/open_id.ts | 39 +++++++++++++++++---------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/app.ts b/src/app.ts index 171ac9222..326c15efd 100644 --- a/src/app.ts +++ b/src/app.ts @@ -61,7 +61,7 @@ app.use(`/icon.png`, express.static(path.join(scriptDir, "public/icon.png"))); app.use(sessionParser); app.use(favicon(`${scriptDir}/../images/app-icons/icon.ico`)); -if (openID.checkOpenIDRequirements()) +if (openID.isOpenIDEnabled()) app.use(auth(openID.generateOAuthConfig())); await assets.register(app); diff --git a/src/services/open_id.ts b/src/services/open_id.ts index 6515fa5ec..1a9b7b1b9 100644 --- a/src/services/open_id.ts +++ b/src/services/open_id.ts @@ -9,7 +9,23 @@ import config from "./config.js"; function isOpenIDEnabled() { - return checkOpenIDRequirements(); + if (config.MultiFactorAuthentication.ssoEnabled) { + if (config.MultiFactorAuthentication.totpEnabled) { + throw new OpenIDError("Cannot enable both OpenID and TOTP!"); + } + + if (config.MultiFactorAuthentication.oauthBaseUrl === "") { + throw new OpenIDError("oauthBaseUrl is undefined!"); + } + if (config.MultiFactorAuthentication.oauthClientId === "") { + throw new OpenIDError("oauthClientId is undefined!"); + } + if (config.MultiFactorAuthentication.oauthClientSecret === "") { + throw new OpenIDError("oauthClientSecret is undefined!"); + } + } + + return config.MultiFactorAuthentication.ssoEnabled; } function isUserSaved() { @@ -36,26 +52,6 @@ function clearSavedUser() { }; } -function checkOpenIDRequirements() { - if (config.MultiFactorAuthentication.ssoEnabled) { - if (config.MultiFactorAuthentication.totpEnabled) { - throw new OpenIDError("Cannot enable both OpenID and TOTP!"); - } - - if (config.MultiFactorAuthentication.oauthBaseUrl === "") { - throw new OpenIDError("oauthBaseUrl is undefined!"); - } - if (config.MultiFactorAuthentication.oauthClientId === "") { - throw new OpenIDError("oauthClientId is undefined!"); - } - if (config.MultiFactorAuthentication.oauthClientSecret === "") { - throw new OpenIDError("oauthClientSecret is undefined!"); - } - } - - return config.MultiFactorAuthentication.ssoEnabled; -} - function getOAuthStatus() { return { success: true, @@ -145,7 +141,6 @@ export default { getOAuthStatus, isOpenIDEnabled, clearSavedUser, - checkOpenIDRequirements, isTokenValid, isUserSaved, };