Fixed authStrategies with multiple domains.
Ylian Saint-Hilaire committed
Nov 24, 2021 at 13:32 UTC
aefe4ece9f8b03c193c8c550e3cfacbbe3ff82b7
1 file changed
+24
-24
webserver.js
+24
-24
@@ -5895,7 +5895,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5895
var options = { consumerKey: domain.authstrategies.twitter.clientid, consumerSecret: domain.authstrategies.twitter.clientsecret };
5896
if (typeof domain.authstrategies.twitter.callbackurl == 'string') { options.callbackURL = domain.authstrategies.twitter.callbackurl; } else { options.callbackURL = url + 'auth-twitter-callback'; }
5897
parent.debug('web', 'Adding Twitter SSO with options: ' + JSON.stringify(options));
5898
- passport.use(new TwitterStrategy(options,
5898
+ passport.use('twitter-' + domain.id, new TwitterStrategy(options,
5899
function (token, tokenSecret, profile, cb) {
5900
parent.debug('web', 'Twitter profile: ' + JSON.stringify(profile));
5901
var user = { sid: '~twitter:' + profile.id, name: profile.displayName, strategy: 'twitter' };
@@ -5906,7 +5906,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5906
obj.app.get(url + 'auth-twitter', function (req, res, next) {
5907
var domain = getDomain(req);
5908
if (domain.passport == null) { next(); return; }
5909
- domain.passport.authenticate('twitter')(req, res, function (err) { console.log('c1', err, req.session); next(); });
5909
+ domain.passport.authenticate('twitter-' + domain.id)(req, res, function (err) { console.log('c1', err, req.session); next(); });
5910
});
5911
obj.app.get(url + 'auth-twitter-callback', function (req, res, next) {
5912
var domain = getDomain(req);
@@ -5918,7 +5918,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5918
res.set('Content-Type', 'text/html');
5919
res.end('<html><head><meta http-equiv="refresh" content=0;url="' + url + '"></head><body></body></html>');
5920
} else {
5921
- domain.passport.authenticate('twitter', { failureRedirect: '/' })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
5921
+ domain.passport.authenticate('twitter-' + domain.id, { failureRedirect: '/' })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
5922
}
5923
}, handleStrategyLogin);
5924
}
@@ -5929,7 +5929,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5929
var options = { clientID: domain.authstrategies.google.clientid, clientSecret: domain.authstrategies.google.clientsecret };
5930
if (typeof domain.authstrategies.google.callbackurl == 'string') { options.callbackURL = domain.authstrategies.google.callbackurl; } else { options.callbackURL = url + 'auth-google-callback'; }
5931
parent.debug('web', 'Adding Google SSO with options: ' + JSON.stringify(options));
5932
- passport.use(new GoogleStrategy(options,
5932
+ passport.use('google-' + domain.id, new GoogleStrategy(options,
5933
function (token, tokenSecret, profile, cb) {
5934
parent.debug('web', 'Google profile: ' + JSON.stringify(profile));
5935
var user = { sid: '~google:' + profile.id, name: profile.displayName, strategy: 'google' };
@@ -5940,12 +5940,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5940
obj.app.get(url + 'auth-google', function (req, res, next) {
5941
var domain = getDomain(req);
5942
if (domain.passport == null) { next(); return; }
5943
- domain.passport.authenticate('google', { scope: ['profile', 'email'] })(req, res, next);
5943
+ domain.passport.authenticate('google-' + domain.id, { scope: ['profile', 'email'] })(req, res, next);
5944
});
5945
obj.app.get(url + 'auth-google-callback', function (req, res, next) {
5946
var domain = getDomain(req);
5947
if (domain.passport == null) { next(); return; }
5948
- domain.passport.authenticate('google', { failureRedirect: '/' })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
5948
+ domain.passport.authenticate('google-' + domain.id, { failureRedirect: '/' })(req, res, function (err) { if (err != null) { console.log(err); } next(); });
5949
}, handleStrategyLogin);
5950
}
5951
@@ -5955,7 +5955,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5955
var options = { clientID: domain.authstrategies.github.clientid, clientSecret: domain.authstrategies.github.clientsecret };
5956
if (typeof domain.authstrategies.github.callbackurl == 'string') { options.callbackURL = domain.authstrategies.github.callbackurl; } else { options.callbackURL = url + 'auth-github-callback'; }
5957
parent.debug('web', 'Adding Github SSO with options: ' + JSON.stringify(options));
5958
- passport.use(new GitHubStrategy(options,
5958
+ passport.use('github-' + domain.id, new GitHubStrategy(options,
5959
function (token, tokenSecret, profile, cb) {
5960
parent.debug('web', 'Github profile: ' + JSON.stringify(profile));
5961
var user = { sid: '~github:' + profile.id, name: profile.displayName, strategy: 'github' };
@@ -5966,12 +5966,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5966
obj.app.get(url + 'auth-github', function (req, res, next) {
5967
var domain = getDomain(req);
5968
if (domain.passport == null) { next(); return; }
5969
- domain.passport.authenticate('github', { scope: ['user:email'] })(req, res, next);
5969
+ domain.passport.authenticate('github-' + domain.id, { scope: ['user:email'] })(req, res, next);
5970
});
5971
obj.app.get(url + 'auth-github-callback', function (req, res, next) {
5972
var domain = getDomain(req);
5973
if (domain.passport == null) { next(); return; }
5974
- domain.passport.authenticate('github', { failureRedirect: '/' })(req, res, next);
5974
+ domain.passport.authenticate('github-' + domain.id, { failureRedirect: '/' })(req, res, next);
5975
}, handleStrategyLogin);
5976
}
5977
@@ -5981,7 +5981,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5981
var options = { clientID: domain.authstrategies.reddit.clientid, clientSecret: domain.authstrategies.reddit.clientsecret };
5982
if (typeof domain.authstrategies.reddit.callbackurl == 'string') { options.callbackURL = domain.authstrategies.reddit.callbackurl; } else { options.callbackURL = url + 'auth-reddit-callback'; }
5983
parent.debug('web', 'Adding Reddit SSO with options: ' + JSON.stringify(options));
5984
- passport.use(new RedditStrategy.Strategy(options,
5984
+ passport.use('reddit-' + domain.id, new RedditStrategy.Strategy(options,
5985
function (token, tokenSecret, profile, cb) {
5986
parent.debug('web', 'Reddit profile: ' + JSON.stringify(profile));
5987
var user = { sid: '~reddit:' + profile.id, name: profile.name, strategy: 'reddit' };
@@ -5992,7 +5992,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5992
obj.app.get(url + 'auth-reddit', function (req, res, next) {
5993
var domain = getDomain(req);
5994
if (domain.passport == null) { next(); return; }
5995
- domain.passport.authenticate('reddit', { state: obj.parent.encodeCookie({ 'p': 'reddit' }, obj.parent.loginCookieEncryptionKey), duration: 'permanent' })(req, res, next);
5995
+ domain.passport.authenticate('reddit-' + domain.id, { state: obj.parent.encodeCookie({ 'p': 'reddit' }, obj.parent.loginCookieEncryptionKey), duration: 'permanent' })(req, res, next);
5996
});
5997
obj.app.get(url + 'auth-reddit-callback', function (req, res, next) {
5998
var domain = getDomain(req);
@@ -6006,7 +6006,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6006
} else {
6007
if (req.query.state != null) {
6008
var c = obj.parent.decodeCookie(req.query.state, obj.parent.loginCookieEncryptionKey, 10); // 10 minute timeout
6009
- if ((c != null) && (c.p == 'reddit')) { domain.passport.authenticate('reddit', { failureRedirect: '/' })(req, res, next); return; }
6009
+ if ((c != null) && (c.p == 'reddit')) { domain.passport.authenticate('reddit-' + domain.id, { failureRedirect: '/' })(req, res, next); return; }
6010
}
6011
next();
6012
}
@@ -6019,7 +6019,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6019
var options = { clientID: domain.authstrategies.azure.clientid, clientSecret: domain.authstrategies.azure.clientsecret, tenant: domain.authstrategies.azure.tenantid };
6020
if (typeof domain.authstrategies.azure.callbackurl == 'string') { options.callbackURL = domain.authstrategies.azure.callbackurl; } else { options.callbackURL = url + 'auth-azure-callback'; }
6021
parent.debug('web', 'Adding Azure SSO with options: ' + JSON.stringify(options));
6022
- passport.use('azure', new AzureOAuth2Strategy(options,
6022
+ passport.use('azure-' + domain.id, new AzureOAuth2Strategy(options,
6023
function (accessToken, refreshtoken, params, profile, done) {
6024
var userex = null;
6025
try { userex = require('jwt-simple').decode(params.id_token, "", true); } catch (ex) { }
@@ -6035,7 +6035,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6035
obj.app.get(url + 'auth-azure', function (req, res, next) {
6036
var domain = getDomain(req);
6037
if (domain.passport == null) { next(); return; }
6038
- domain.passport.authenticate('azure', { state: obj.parent.encodeCookie({ 'p': 'azure' }, obj.parent.loginCookieEncryptionKey) })(req, res, next);
6038
+ domain.passport.authenticate('azure-' + domain.id, { state: obj.parent.encodeCookie({ 'p': 'azure' }, obj.parent.loginCookieEncryptionKey) })(req, res, next);
6039
});
6040
obj.app.get(url + 'auth-azure-callback', function (req, res, next) {
6041
var domain = getDomain(req);
@@ -6049,7 +6049,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6049
} else {
6050
if (req.query.state != null) {
6051
var c = obj.parent.decodeCookie(req.query.state, obj.parent.loginCookieEncryptionKey, 10); // 10 minute timeout
6052
- if ((c != null) && (c.p == 'azure')) { domain.passport.authenticate('azure', { failureRedirect: '/' })(req, res, next); return; }
6052
+ if ((c != null) && (c.p == 'azure')) { domain.passport.authenticate('azure-' + domain.id, { failureRedirect: '/' })(req, res, next); return; }
6053
}
6054
next();
6055
}
@@ -6073,7 +6073,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6073
parent.debug('web', 'Adding SAML SSO with options: ' + JSON.stringify(options));
6074
options.cert = cert.toString().split('-----BEGIN CERTIFICATE-----').join('').split('-----END CERTIFICATE-----').join('');
6075
const SamlStrategy = require('passport-saml').Strategy;
6076
- passport.use(new SamlStrategy(options,
6076
+ passport.use('saml-' + domain.id, new SamlStrategy(options,
6077
function (profile, done) {
6078
parent.debug('web', 'SAML profile: ' + JSON.stringify(profile));
6079
if (typeof profile.nameID != 'string') { return done(); }
@@ -6086,12 +6086,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6086
obj.app.get(url + 'auth-saml', function (req, res, next) {
6087
var domain = getDomain(req);
6088
if (domain.passport == null) { next(); return; }
6089
- domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
6089
+ domain.passport.authenticate('saml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6090
});
6091
obj.app.post(url + 'auth-saml-callback', function (req, res, next) {
6092
var domain = getDomain(req);
6093
if (domain.passport == null) { next(); return; }
6094
- domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
6094
+ domain.passport.authenticate('saml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6095
}, handleStrategyLogin);
6096
}
6097
}
@@ -6113,7 +6113,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6113
parent.debug('web', 'Adding Intel SSO with options: ' + JSON.stringify(options));
6114
options.cert = cert.toString().split('-----BEGIN CERTIFICATE-----').join('').split('-----END CERTIFICATE-----').join('');
6115
const SamlStrategy = require('passport-saml').Strategy;
6116
- passport.use(new SamlStrategy(options,
6116
+ passport.use('isaml-' + domain.id, new SamlStrategy(options,
6117
function (profile, done) {
6118
parent.debug('web', 'Intel profile: ' + JSON.stringify(profile));
6119
if (typeof profile.nameID != 'string') { return done(); }
@@ -6128,12 +6128,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6128
obj.app.get(url + 'auth-intel', function (req, res, next) {
6129
var domain = getDomain(req);
6130
if (domain.passport == null) { next(); return; }
6131
- domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
6131
+ domain.passport.authenticate('isaml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6132
});
6133
obj.app.post(url + 'auth-intel-callback', function (req, res, next) {
6134
var domain = getDomain(req);
6135
if (domain.passport == null) { next(); return; }
6136
- domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
6136
+ domain.passport.authenticate('isaml-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6137
}, handleStrategyLogin);
6138
}
6139
}
@@ -6154,7 +6154,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6154
parent.debug('web', 'Adding JumpCloud SSO with options: ' + JSON.stringify(options));
6155
options.cert = cert.toString().split('-----BEGIN CERTIFICATE-----').join('').split('-----END CERTIFICATE-----').join('');
6156
const SamlStrategy = require('passport-saml').Strategy;
6157
- passport.use(new SamlStrategy(options,
6157
+ passport.use('jumpcloud-' + domain.id, new SamlStrategy(options,
6158
function (profile, done) {
6159
parent.debug('web', 'JumpCloud profile: ' + JSON.stringify(profile));
6160
if (typeof profile.nameID != 'string') { return done(); }
@@ -6167,12 +6167,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
6167
obj.app.get(url + 'auth-jumpcloud', function (req, res, next) {
6168
var domain = getDomain(req);
6169
if (domain.passport == null) { next(); return; }
6170
- domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
6170
+ domain.passport.authenticate('jumpcloud-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6171
});
6172
obj.app.post(url + 'auth-jumpcloud-callback', function (req, res, next) {
6173
var domain = getDomain(req);
6174
if (domain.passport == null) { next(); return; }
6175
- domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
6175
+ domain.passport.authenticate('jumpcloud-' + domain.id, { failureRedirect: '/', failureFlash: true })(req, res, next);
6176
}, handleStrategyLogin);
6177
}
6178
}