Skip to content

Commit

Permalink
[mirotalkbro] - Enable OIDC support for alias domains with dynamic ba…
Browse files Browse the repository at this point in the history
…seURL
  • Loading branch information
miroslavpejic85 committed Jan 31, 2025
1 parent 428194e commit 4e8c73c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4e8c73c

Please sign in to comment.