fix oidc reauth #6132

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Jun 1, 2024 at 20:31 UTC c67a76bcc27bfe2b62b9043e8dddec5ba0a8b449
1 file changed +10 -3
webserver.js
+10 -3
@@ -2808,8 +2808,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
2808 obj.parent.DispatchEvent(targets, obj, loginEvent);
2809 parent.authLog('handleStrategyLogin', `${req.user.strategy.toUpperCase()}: LOGIN SUCCESS: USER: "${req.user.sid}"`);
2810 }
2811 + } else if (req.session && req.session.userid && obj.users[req.session.userid]) {
2812 + parent.authLog('handleStrategyLogin', `User Already Authorised "${(req.session.passport && req.session.passport.user) ? req.session.passport.user : req.session.userid }"`);
2813 } else {
2812 - parent.authLog('handleStrategyLogin', `LOGIN FAILED: NO USER: REQUEST CONTAINS NO USER OR SID`);
2814 + parent.authLog('handleStrategyLogin', `LOGIN FAILED: REQUEST CONTAINS NO USER OR SID`);
2815 }
2816 //res.redirect(domain.url); // This does not handle cookie correctly.
2817 res.set('Content-Type', 'text/html');
@@ -6782,7 +6784,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6784 obj.app.get(redirectPath, obj.bodyParser.urlencoded({ extended: false }), function (req, res, next) {
6785 var domain = getDomain(req);
6786 if (domain.passport == null) { next(); return; }
6785 - domain.passport.authenticate(`oidc-${domain.id}`, { failureRedirect: '/', failureFlash: true })(req, res, next);
6787 + if (req.session && req.session.userid) { next(); return; } // already logged in so dont authenticate just carry on
6788 + if (req.session && req.session['oidc-' + domain.id]) { // we have a request to login so do authenticate
6789 + domain.passport.authenticate(`oidc-${domain.id}`, { failureRedirect: '/', failureFlash: true })(req, res, next);
6790 + } else { // no idea so carry on
6791 + next(); return;
6792 + }
6793 }, handleStrategyLogin);
6794 }
6795
@@ -7423,7 +7430,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
7430
7431 // Create client and overwrite in options
7432 let client = new issuer.Client(strategy.client)
7426 - strategy.options = Object.assign(strategy.options, { 'client': client });
7433 + strategy.options = Object.assign(strategy.options, { 'client': client, sessionKey: 'oidc-' + domain.id });
7434 strategy.client = client.metadata
7435 strategy.obj.client = client
7436