From 7929aaf91ad6241b702ba05d8490f28dfcb56cd6 Mon Sep 17 00:00:00 2001 From: Jin <22962980+JYC333@users.noreply.github.com> Date: Fri, 28 Mar 2025 03:43:44 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20returen=20missing=20vars?= =?UTF-8?q?=20for=20oauth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/auth.ts | 2 +- src/services/open_id.ts | 32 +++++++++++++++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/services/auth.ts b/src/services/auth.ts index a01df0307..69bffa73b 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -31,7 +31,7 @@ function checkAuth(req: Request, res: Response, next: NextFunction) { res.redirect('/login'); }); return; - } else if (openID.isOpenIDEnabled()) { + } else if (currentSsoStatus) { if (req.oidc?.isAuthenticated() && req.session.loggedIn) { next(); return; diff --git a/src/services/open_id.ts b/src/services/open_id.ts index ab04e206d..48d0f8d10 100644 --- a/src/services/open_id.ts +++ b/src/services/open_id.ts @@ -1,4 +1,3 @@ -import OpenIDError from "../errors/open_id_error.js"; import type { NextFunction, Request, Response } from "express"; import openIDEncryption from "./encryption/open_id_encryption.js"; import sqlInit from "./sql_init.js"; @@ -8,24 +7,22 @@ import sql from "./sql.js"; import config from "./config.js"; -function isOpenIDEnabled() { - 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!"); - } +function checkOpenIDConfig() { + let missingVars: string[] = [] + if (config.MultiFactorAuthentication.oauthBaseUrl === "") { + missingVars.push("oauthBaseUrl"); } + if (config.MultiFactorAuthentication.oauthClientId === "") { + missingVars.push("oauthClientId"); + } + if (config.MultiFactorAuthentication.oauthClientSecret === "") { + missingVars.push("oauthClientSecret"); + } + return missingVars; +} - return config.MultiFactorAuthentication.ssoEnabled; +function isOpenIDEnabled() { + return checkOpenIDConfig().length > 0 ? false : true; } function isUserSaved() { @@ -58,6 +55,7 @@ function getOAuthStatus() { name: getUsername(), email: getUserEmail(), enabled: isOpenIDEnabled(), + missingVars: checkOpenIDConfig() }; }