Callback redirect and mapping email attributes
This commit is contained in:
parent
3e1352729e
commit
f58b6ae34a
3 changed files with 37 additions and 15 deletions
41
library.js
41
library.js
|
|
@ -27,7 +27,7 @@
|
||||||
samlObj = new passportSAML({
|
samlObj = new passportSAML({
|
||||||
path: meta.config['sso:saml:callbackpath'],
|
path: meta.config['sso:saml:callbackpath'],
|
||||||
entryPoint: meta.config['sso:saml:idpentrypoint'],
|
entryPoint: meta.config['sso:saml:idpentrypoint'],
|
||||||
issuer: 'passport-saml',
|
issuer: meta.config['sso:saml:issuer'],
|
||||||
callbackUrl: nconf.get('url') + meta.config['sso:saml:callbackpath']
|
callbackUrl: nconf.get('url') + meta.config['sso:saml:callbackpath']
|
||||||
},
|
},
|
||||||
function(profile, done) {
|
function(profile, done) {
|
||||||
|
|
@ -40,10 +40,10 @@
|
||||||
mail: profile.mail,
|
mail: profile.mail,
|
||||||
eduPersonAffiliation: profile.eduPersonAffiliation,
|
eduPersonAffiliation: profile.eduPersonAffiliation,
|
||||||
email: profile.email,
|
email: profile.email,
|
||||||
username: profile.displayName
|
username: profile.eduPersonNickname
|
||||||
};
|
};
|
||||||
|
|
||||||
SAML.login(user.nameID,user.username,function(err, user) {
|
SAML.login(user,function(err, user) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
|
|
@ -81,9 +81,18 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
app.post(meta.config['sso:saml:callbackpath'],
|
app.post(meta.config['sso:saml:callbackpath'],
|
||||||
passport.authenticate('saml', { successRedirect: '/',failureRedirect: '/', failureFlash: true })
|
passport.authenticate('saml'),
|
||||||
|
function(req, res, next){
|
||||||
|
if (meta.config['sso:saml:loginsuccessredirecturl']){
|
||||||
|
res.redirect(meta.config['sso:saml:loginsuccessredirecturl']);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
res.redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,9 +117,9 @@
|
||||||
callback(null, strategies);
|
callback(null, strategies);
|
||||||
};
|
};
|
||||||
|
|
||||||
SAML.login = function(samlid,username, callback) {
|
SAML.login = function(userdata, callback) {
|
||||||
|
|
||||||
SAML.getUidBySAMLId(samlid, function(err, uid) {
|
SAML.getUidBySAMLId(userdata.username, function(err, uid) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
@ -122,14 +131,24 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
console.log({
|
||||||
|
username: userdata.username,
|
||||||
|
email: userdata.email,
|
||||||
|
fullname : userdata.cn + " " + userdata.sn
|
||||||
|
|
||||||
|
});
|
||||||
// New User
|
// New User
|
||||||
user.create({username: username}, function(err, uid) {
|
user.create({
|
||||||
|
username: userdata.username,
|
||||||
|
email: userdata.email,
|
||||||
|
fullname : userdata.cn + " " + userdata.sn
|
||||||
|
|
||||||
|
}, function(err, uid) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
// Save twitter-specific information to the user
|
user.setUserField(uid, 'samlid', userdata.username);
|
||||||
user.setUserField(uid, 'samlid', samlid);
|
db.setObjectField('samlid:uid', userdata.username, uid);
|
||||||
db.setObjectField('samlid:uid', samlid, uid);
|
|
||||||
|
|
||||||
callback(null, {
|
callback(null, {
|
||||||
uid: uid
|
uid: uid
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nodebb-plugin-sso-saml",
|
"name": "nodebb-plugin-sso-saml",
|
||||||
"version": "0.0.1",
|
"version": "0.0.3",
|
||||||
"description": "NodeBB SAML SSO",
|
"description": "NodeBB SAML SSO",
|
||||||
"main": "library.js",
|
"main": "library.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
@ -30,5 +30,5 @@
|
||||||
"passport-saml": "~0.5.3"
|
"passport-saml": "~0.5.3"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/GeographicaGS/nodebb-plugin-sso-saml.git",
|
"homepage": "https://github.com/GeographicaGS/nodebb-plugin-sso-saml.git",
|
||||||
"_id": "nodebb-plugin-sso-saml@0.0.1"
|
"_id": "nodebb-plugin-sso-saml@0.0.2"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@
|
||||||
|
|
||||||
<input type="text" data-field="sso:saml:servercrt" title="Server CRT file" class="form-control input-md" placeholder="Server CRT file">
|
<input type="text" data-field="sso:saml:servercrt" title="Server CRT file" class="form-control input-md" placeholder="Server CRT file">
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<input type="text" data-field="sso:saml:loginsuccessredirecturl" title="URL to redirect after a successfull login" class="form-control input-md" placeholder="URL to redirect after a successfull login. Leave empty to redirect to /. ">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue