From 4e8c73cd2d51bc9e4c4236948b473672333c40e8 Mon Sep 17 00:00:00 2001 From: Miroslav Pejic Date: Sat, 1 Feb 2025 00:34:51 +0100 Subject: [PATCH] [mirotalkbro] - Enable OIDC support for alias domains with dynamic baseURL --- app/server.js | 29 ++++++++++++++++++++++------- package.json | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/server.js b/app/server.js index 04f3e61..cae6eaa 100644 --- a/app/server.js +++ b/app/server.js @@ -231,14 +231,29 @@ app.use((err, req, res, next) => { } }); -// OpenID Connect +// OpenID Connect - Dynamically set baseURL based on incoming host and protocol if (OIDC.enabled) { - try { - app.use(auth(OIDC.config)); - } catch (err) { - log.error(err); - process.exit(1); - } + const getDynamicConfig = (host, protocol) => { + const baseURL = `${protocol}://${host}`; + log.debug('OIDC baseURL', baseURL); + return { + ...OIDC.config, + baseURL, + }; + }; + + // Apply the authentication middleware using dynamic baseURL configuration + app.use((req, res, next) => { + const host = req.headers.host; + const protocol = req.protocol === 'https' ? 'https' : 'http'; + const dynamicOIDCConfig = getDynamicConfig(host, protocol); + try { + auth(dynamicOIDCConfig)(req, res, next); + } catch (err) { + log.error('OIDC Auth Middleware Error', err); + process.exit(1); + } + }); } app.get('/profile', OIDCAuth, (req, res) => { diff --git a/package.json b/package.json index 7e94f61..475fc13 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "Miroslav Pejic", "license": "AGPLv3", "dependencies": { - "@sentry/node": "^8.51.0", + "@sentry/node": "^8.53.0", "compression": "^1.7.5", "cors": "^2.8.5", "dotenv": "^16.4.7",