fix passport failureRedirect for subdomain paths

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

si458 committed Jun 11, 2024 at 20:38 UTC 42a07e9d74bb93ab6843622e380dc954d449e5aa
1 file changed +12 -12
webserver.js
+12 -12
@@ -6710,7 +6710,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6710 res.set('Content-Type', 'text/html');
6711 res.end('<html><head><meta http-equiv="refresh" content=0;url="' + url + '"></head><body></body></html>');
6712 } else {
6713 - domain.passport.authenticate('twitter-' + domain.id, { failureRedirect: '/' })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
6713 + domain.passport.authenticate('twitter-' + domain.id, { failureRedirect: url })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
6714 }
6715 }, handleStrategyLogin);
6716 }
@@ -6725,7 +6725,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6725 obj.app.get(url + 'auth-google-callback', function (req, res, next) {
6726 var domain = getDomain(req);
6727 if (domain.passport == null) { next(); return; }
6728 - domain.passport.authenticate('google-' + domain.id, { failureRedirect: '/' })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
6728 + domain.passport.authenticate('google-' + domain.id, { failureRedirect: url })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
6729 }, handleStrategyLogin);
6730 }
6731
@@ -6739,7 +6739,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6739 obj.app.get(url + 'auth-github-callback', function (req, res, next) {
6740 var domain = getDomain(req);
6741 if (domain.passport == null) { next(); return; }
6742 - domain.passport.authenticate('github-' + domain.id, { failureRedirect: '/' })(req, res, next);
6742 + domain.passport.authenticate('github-' + domain.id, { failureRedirect: url })(req, res, next);
6743 }, handleStrategyLogin);
6744 }
6745
@@ -6762,7 +6762,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6762 } else {
6763 if (req.query.state != null) {
6764 var c = obj.parent.decodeCookie(req.query.state, obj.parent.loginCookieEncryptionKey, 10); // 10 minute timeout
6765 - if ((c != null) && (c.p == 'azure')) { domain.passport.authenticate('azure-' + domain.id, { failureRedirect: '/' })(req, res, next); return; }
6765 + if ((c != null) && (c.p == 'azure')) { domain.passport.authenticate('azure-' + domain.id, { failureRedirect: url })(req, res, next); return; }
6766 }
6767 next();
6768 }
@@ -6776,7 +6776,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6776 obj.app.get(authURL, function (req, res, next) {
6777 var domain = getDomain(req);
6778 if (domain.passport == null) { next(); return; }
6779 - domain.passport.authenticate(`oidc-${domain.id}`, { failureRedirect: '/', failureFlash: true })(req, res, next);
6779 + domain.passport.authenticate(`oidc-${domain.id}`, { failureRedirect: url, failureFlash: true })(req, res, next);
6780 });
6781 let redirectPath;
6782 if (typeof domain.authstrategies.oidc.client.redirect_uri == 'string') {
@@ -6792,7 +6792,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6792 if (domain.passport == null) { next(); return; }
6793 if (req.session && req.session.userid) { next(); return; } // already logged in so dont authenticate just carry on
6794 if (req.session && req.session['oidc-' + domain.id]) { // we have a request to login so do authenticate
6795 - domain.passport.authenticate(`oidc-${domain.id}`, { failureRedirect: '/', failureFlash: true })(req, res, next);
6795 + domain.passport.authenticate(`oidc-${domain.id}`, { failureRedirect: url, failureFlash: true })(req, res, next);
6796 } else { // no idea so carry on
6797 next(); return;
6798 }
@@ -6804,12 +6804,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6804 obj.app.get(url + 'auth-saml', function (req, res, next) {
6805 var domain = getDomain(req);
6806 if (domain.passport == null) { next(); return; }
6807 - domain.passport.authenticate('saml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6807 + domain.passport.authenticate('saml-' + domain.id, { failureRedirect: url, failureFlash: true })(req, res, next);
6808 });
6809 obj.app.post(url + 'auth-saml-callback', obj.bodyParser.urlencoded({ extended: false }), function (req, res, next) {
6810 var domain = getDomain(req);
6811 if (domain.passport == null) { next(); return; }
6812 - domain.passport.authenticate('saml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6812 + domain.passport.authenticate('saml-' + domain.id, { failureRedirect: url, failureFlash: true })(req, res, next);
6813 }, handleStrategyLogin);
6814 }
6815
@@ -6818,12 +6818,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6818 obj.app.get(url + 'auth-intel', function (req, res, next) {
6819 var domain = getDomain(req);
6820 if (domain.passport == null) { next(); return; }
6821 - domain.passport.authenticate('isaml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6821 + domain.passport.authenticate('isaml-' + domain.id, { failureRedirect: url, failureFlash: true })(req, res, next);
6822 });
6823 obj.app.post(url + 'auth-intel-callback', obj.bodyParser.urlencoded({ extended: false }), function (req, res, next) {
6824 var domain = getDomain(req);
6825 if (domain.passport == null) { next(); return; }
6826 - domain.passport.authenticate('isaml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6826 + domain.passport.authenticate('isaml-' + domain.id, { failureRedirect: url, failureFlash: true })(req, res, next);
6827 }, handleStrategyLogin);
6828 }
6829
@@ -6832,12 +6832,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6832 obj.app.get(url + 'auth-jumpcloud', function (req, res, next) {
6833 var domain = getDomain(req);
6834 if (domain.passport == null) { next(); return; }
6835 - domain.passport.authenticate('jumpcloud-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6835 + domain.passport.authenticate('jumpcloud-' + domain.id, { failureRedirect: url, failureFlash: true })(req, res, next);
6836 });
6837 obj.app.post(url + 'auth-jumpcloud-callback', obj.bodyParser.urlencoded({ extended: false }), function (req, res, next) {
6838 var domain = getDomain(req);
6839 if (domain.passport == null) { next(); return; }
6840 - domain.passport.authenticate('jumpcloud-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6840 + domain.passport.authenticate('jumpcloud-' + domain.id, { failureRedirect: url, failureFlash: true })(req, res, next);
6841 }, handleStrategyLogin);
6842 }
6843 }