Started work on added JumpCloud support.

Ylian Saint-Hilaire committed May 19, 2020 at 19:02 UTC 7b1c553ca83bcf58178cfe8a24aa4e8b72e00e52
6 files changed +42 -2
meshcentral.js
+1
@@ -2556,6 +2556,7 @@ function mainStart() {
2556 if ((typeof config.domains[i].authstrategies.google == 'object') && (typeof config.domains[i].authstrategies.google.clientid == 'string') && (typeof config.domains[i].authstrategies.google.clientsecret == 'string') && (passport.indexOf('passport-google-oauth20') == -1)) { passport.push('passport-google-oauth20'); }
2557 if ((typeof config.domains[i].authstrategies.github == 'object') && (typeof config.domains[i].authstrategies.github.clientid == 'string') && (typeof config.domains[i].authstrategies.github.clientsecret == 'string') && (passport.indexOf('passport-github2') == -1)) { passport.push('passport-github2'); }
2558 if ((typeof config.domains[i].authstrategies.reddit == 'object') && (typeof config.domains[i].authstrategies.reddit.clientid == 'string') && (typeof config.domains[i].authstrategies.reddit.clientsecret == 'string') && (passport.indexOf('passport-reddit') == -1)) { passport.push('passport-reddit'); }
2559 + if ((typeof config.domains[i].authstrategies.saml == 'object') || (typeof config.domains[i].authstrategies.jumpcloud == 'object')) { passport.push('passport-saml'); }
2560 }
2561 if ((config.domains[i].sessionrecording != null) && (config.domains[i].sessionrecording.index == true)) { recordingIndex = true; }
2562 }
public/images/login/jumpcloud32.png
Binary files /dev/null and b/public/images/login/jumpcloud32.png differ
public/images/login/jumpcloud64.png
Binary files /dev/null and b/public/images/login/jumpcloud64.png differ
views/default.handlebars
+2 -1
@@ -886,7 +886,7 @@
886 </td>
887 <td style=width:20px></td>
888 <td style=width:200px;position:relative valign=top>
889 - <img id="p30userAuthServiceLogo" loading="lazy" style="display:none" class=userAuthStrategyLogo src=images/login/reddit64.png width=64 height=64>
889 + <img id="p30userAuthServiceLogo" loading="lazy" style="display:none" class=userAuthStrategyLogo width=64 height=64>
890 <picture id=MainUserImage style=border-width:0px;height:200px;width:200px;float:right>
891 <source type="image/webp" width=200 height=200 srcset="images/webp/user-256.webp" />
892 <img alt="" width=200 height=200 src=images/user-256.png />
@@ -10884,6 +10884,7 @@
10884 else if (shortuserid.startsWith('~google:')) { QV('p30userAuthServiceLogo', true); Q('p30userAuthServiceLogo').src = 'images/login/google64.png';; }
10885 else if (shortuserid.startsWith('~github:')) { QV('p30userAuthServiceLogo', true); Q('p30userAuthServiceLogo').src = 'images/login/github64.png';; }
10886 else if (shortuserid.startsWith('~reddit:')) { QV('p30userAuthServiceLogo', true); Q('p30userAuthServiceLogo').src = 'images/login/reddit64.png';; }
10887 + else if (shortuserid.startsWith('~jumpcloud:')) { QV('p30userAuthServiceLogo', true); Q('p30userAuthServiceLogo').src = 'images/login/jumpcloud64.png';; }
10888 else if (shortuserid.startsWith('~intel:')) { QV('p30userAuthServiceLogo', true); Q('p30userAuthServiceLogo').src = 'images/login/intel64.png';; }
10889 else { QV('p30userAuthServiceLogo', false); }
10890
views/login.handlebars
+2
@@ -77,6 +77,7 @@
77 <a id="auth-google" href="auth-google" style="display:none"><img src="images/login/google32.png" loading="lazy" width="32" height="32" style="margin-left:3px;margin-right:3px;border-radius:3px;box-shadow:2px 2px 5px black;cursor:pointer" title="Sign-in using Google" /></a>
78 <a id="auth-github" href="auth-github" style="display:none"><img src="images/login/github32.png" loading="lazy" width="32" height="32" style="margin-left:3px;margin-right:3px;border-radius:3px;box-shadow:2px 2px 5px black;cursor:pointer" title="Sign-in using GitHub" /></a>
79 <a id="auth-reddit" href="auth-reddit" style="display:none"><img src="images/login/reddit32.png" loading="lazy" width="32" height="32" style="margin-left:3px;margin-right:3px;border-radius:3px;box-shadow:2px 2px 5px black;cursor:pointer" title="Sign-in using Reddit" /></a>
80 + <a id="auth-jumpcloud" href="auth-jumpcloud" style="display:none"><img src="images/login/jumpcloud32.png" loading="lazy" width="32" height="32" style="margin-left:3px;margin-right:3px;border-radius:3px;box-shadow:2px 2px 5px black;cursor:pointer" title="Sign-in using JumpCloud" /></a>
81 </div>
82 </form>
83 </div>
@@ -384,6 +385,7 @@
385 if (authStrategies.indexOf('google') >= 0) { QV('auth-google', true); }
386 if (authStrategies.indexOf('github') >= 0) { QV('auth-github', true); }
387 if (authStrategies.indexOf('reddit') >= 0) { QV('auth-reddit', true); }
388 + if (authStrategies.indexOf('jumpcloud') >= 0) { QV('auth-jumpcloud', true); }
389 }
390
391 // Display the welcome text
webserver.js
+37 -1
@@ -2115,6 +2115,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2115 if ((typeof domain.authstrategies.google == 'object') && (typeof domain.authstrategies.google.clientid == 'string') && (typeof domain.authstrategies.google.clientsecret == 'string')) { authStrategies.push('google'); }
2116 if ((typeof domain.authstrategies.github == 'object') && (typeof domain.authstrategies.github.clientid == 'string') && (typeof domain.authstrategies.github.clientsecret == 'string')) { authStrategies.push('github'); }
2117 if ((typeof domain.authstrategies.reddit == 'object') && (typeof domain.authstrategies.reddit.clientid == 'string') && (typeof domain.authstrategies.reddit.clientsecret == 'string')) { authStrategies.push('reddit'); }
2118 + if ((typeof domain.authstrategies.jumpcloud == 'object')) { authStrategies.push('jumpcloud'); }
2119 if ((typeof domain.authstrategies.intel == 'object') && (typeof domain.authstrategies.intel.clientid == 'string') && (typeof domain.authstrategies.intel.clientsecret == 'string')) { authStrategies.push('intel'); }
2120 }
2121
@@ -4188,7 +4189,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4189 ));
4190 obj.app.get(url + 'auth-reddit', function (req, res, next) {
4191 req.session.rstate = obj.crypto.randomBytes(32).toString('hex');
4191 - domain.passport.authenticate('reddit', { state: req.session.rstate, duration: 'permanent' })(req, res, next); // TODO: Replace 'rcookie' with a time-limited cookie
4192 + domain.passport.authenticate('reddit', { state: req.session.rstate, duration: 'permanent' })(req, res, next);
4193 });
4194 obj.app.get(url + 'auth-reddit-callback', function (req, res, next) {
4195 if ((Object.keys(req.session).length == 0) && (req.query.nmr == null)) {
@@ -4208,6 +4209,41 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4209 }
4210 }, handleStrategyLogin);
4211 }
4212 +
4213 + // JumpCloud
4214 + if (typeof domain.authstrategies.jumpcloud == 'object') {
4215 + const SamlStrategy = require('passport-saml').Strategy;
4216 +
4217 + var options = {
4218 + path: url + 'auth-jumpcloud-callback',
4219 + entryPoint: domain.authstrategies.jumpcloud.idpurl,
4220 + issuer: 'passport-saml'
4221 + };
4222 +
4223 + if (domain.authstrategies.jumpcloud.cert) {
4224 + var cert = obj.fs.readFileSync(obj.path.join(obj.parent.datapath, domain.authstrategies.jumpcloud.cert));
4225 + if (cert != null) { options.cert = cert.toString().split('-----BEGIN CERTIFICATE-----').join('').split('-----END CERTIFICATE-----').join(''); }
4226 + //console.log(options);
4227 + }
4228 +
4229 + passport.use(new SamlStrategy(options,
4230 + function (profile, done) {
4231 + //var user = { id: 'user/' + domain.id + '/~reddit:' + profile.id, name: profile.name };
4232 + //if ((typeof profile.emails == 'object') && (profile.emails[0] != null) && (typeof profile.emails[0].value == 'string')) { user.email = profile.emails[0].value; }
4233 + console.log('JumpCloud Profile', profile);
4234 + var user = { id: 'user/' + domain.id + '/~jumpcloud:' + profile.id, name: profile.name };
4235 + return done(null, user);
4236 + }
4237 + ));
4238 + obj.app.get(url + 'auth-jumpcloud', function (req, res, next) {
4239 + console.log('auth-jumpcloud');
4240 + domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
4241 + });
4242 + obj.app.get(url + 'auth-jumpcloud-callback', function (req, res, next) {
4243 + console.log('auth-jumpcloud-callback');
4244 + domain.passport.authenticate('saml', { failureRedirect: '/', failureFlash: true })(req, res, next);
4245 + });
4246 + }
4247 }
4248
4249 // Server redirects