create samlObj in callback
This commit is contained in:
parent
72692f6cef
commit
b57aece656
1 changed files with 93 additions and 97 deletions
190
library.js
190
library.js
|
|
@ -34,6 +34,99 @@
|
||||||
meta.settings.get('sso_saml', function(err, options) {
|
meta.settings.get('sso_saml', function(err, options) {
|
||||||
console.log('[sso-saml] got options', options);
|
console.log('[sso-saml] got options', options);
|
||||||
master_config = options;
|
master_config = options;
|
||||||
|
if (master_config.idp_entry_point && master_config.callback_path && master_config.issuer && master_config.metadata) {
|
||||||
|
console.log("creating samlObj");
|
||||||
|
samlObj = new passportSAML({
|
||||||
|
path: master_config.callback_path,
|
||||||
|
entryPoint: master_config.idp_entry_point,
|
||||||
|
issuer: master_config.issuer,
|
||||||
|
callbackUrl: nconf.get('url') + master_config.callback_path,
|
||||||
|
disableRequestedAuthnContext: true,
|
||||||
|
identifierFormat: null
|
||||||
|
},
|
||||||
|
function(profile, done) {
|
||||||
|
console.log("[sso-saml] profile, ", profile);
|
||||||
|
var user = {
|
||||||
|
nameID: profile.nameID,
|
||||||
|
nameIDFormat: profile.nameIDFormat,
|
||||||
|
sn: profile['urn:oid:2.5.4.4'], // sn
|
||||||
|
//sn: profile.sn,
|
||||||
|
cn: profile['urn:oid:2.5.4.42'], // givenname
|
||||||
|
//cn: profile.cn,
|
||||||
|
//mail: profile.mail,
|
||||||
|
//eduPersonAffiliation: profile.eduPersonAffiliation,
|
||||||
|
email: profile.mail,
|
||||||
|
//email: profile.email,
|
||||||
|
username: profile['urn:oid:1.3.6.1.4.1.5923.1.1.1.2'], // eduPersonNickname
|
||||||
|
//username: profile.eduPersonNickname
|
||||||
|
};
|
||||||
|
|
||||||
|
SAML.login(user,function(err, user) {
|
||||||
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
done(null, user);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (samlObj){
|
||||||
|
|
||||||
|
if (master_config.metadata) {
|
||||||
|
params.router.get(master_config.metadata, function(req, res) {
|
||||||
|
if (master_config.server_crt){
|
||||||
|
var cert = fs.readFileSync(master_config.server_crt, 'utf-8');
|
||||||
|
res.header("Content-Type", "application/xml");
|
||||||
|
res.send(samlObj.generateServiceProviderMetadata(cert))
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
res.send("No servercrt specified. Please enter it at nodebb admin panel.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
params.router.post(master_config.callback_path,
|
||||||
|
passport.authenticate('saml'),
|
||||||
|
function(req, res, next){
|
||||||
|
if (master_config.login_redirect_url){
|
||||||
|
res.redirect(master_config.login_redirect_url);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
res.redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
if (master_config.logout_url) {
|
||||||
|
|
||||||
|
params.router.get(master_config.logout_url,function(req,res){
|
||||||
|
if (req.user && parseInt(req.user.uid, 10) > 0) {
|
||||||
|
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
|
||||||
|
|
||||||
|
var ws = module.parent.require('./socket.io');
|
||||||
|
ws.logoutUser(req.user.uid);
|
||||||
|
|
||||||
|
req.logout();
|
||||||
|
|
||||||
|
if (master_config.logout_redirect_url){
|
||||||
|
res.redirect(master_config.logout_redirect_url);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
res.redirect("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("[sso-saml] Cannot create samlObj");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
params.router.get('/admin/plugins/sso-saml', params.middleware.admin.buildHeader, render);
|
params.router.get('/admin/plugins/sso-saml', params.middleware.admin.buildHeader, render);
|
||||||
|
|
@ -55,104 +148,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
getStrategy(strategies, callback) {
|
getStrategy(strategies, callback) {
|
||||||
|
|
||||||
if (master_config.idp_entry_point && master_config.callback_path && master_config.issuer && master_config.metadata) {
|
|
||||||
console.log("creating samlObj");
|
|
||||||
samlObj = new passportSAML({
|
|
||||||
path: master_config.callback_path,
|
|
||||||
entryPoint: master_config.idp_entry_point,
|
|
||||||
issuer: master_config.issuer,
|
|
||||||
callbackUrl: nconf.get('url') + master_config.callback_path,
|
|
||||||
disableRequestedAuthnContext: true,
|
|
||||||
identifierFormat: null
|
|
||||||
},
|
|
||||||
function(profile, done) {
|
|
||||||
console.log("[sso-saml] profile, ", profile);
|
|
||||||
var user = {
|
|
||||||
nameID: profile.nameID,
|
|
||||||
nameIDFormat: profile.nameIDFormat,
|
|
||||||
sn: profile['urn:oid:2.5.4.4'], // sn
|
|
||||||
//sn: profile.sn,
|
|
||||||
cn: profile['urn:oid:2.5.4.42'], // givenname
|
|
||||||
//cn: profile.cn,
|
|
||||||
//mail: profile.mail,
|
|
||||||
//eduPersonAffiliation: profile.eduPersonAffiliation,
|
|
||||||
email: profile.mail,
|
|
||||||
//email: profile.email,
|
|
||||||
username: profile['urn:oid:1.3.6.1.4.1.5923.1.1.1.2'], // eduPersonNickname
|
|
||||||
//username: profile.eduPersonNickname
|
|
||||||
};
|
|
||||||
|
|
||||||
SAML.login(user,function(err, user) {
|
|
||||||
if (err) {
|
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
done(null, user);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (samlObj){
|
if (samlObj){
|
||||||
|
|
||||||
if (master_config.metadata) {
|
|
||||||
params.router.get(master_config.metadata, function(req, res) {
|
|
||||||
if (master_config.server_crt){
|
|
||||||
var cert = fs.readFileSync(master_config.server_crt, 'utf-8');
|
|
||||||
res.header("Content-Type", "application/xml");
|
|
||||||
res.send(samlObj.generateServiceProviderMetadata(cert))
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
res.send("No servercrt specified. Please enter it at nodebb admin panel.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
params.router.post(master_config.callback_path,
|
|
||||||
passport.authenticate('saml'),
|
|
||||||
function(req, res, next){
|
|
||||||
if (master_config.login_redirect_url){
|
|
||||||
res.redirect(master_config.login_redirect_url);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
res.redirect("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
if (master_config.logout_url) {
|
|
||||||
|
|
||||||
params.router.get(master_config.logout_url,function(req,res){
|
|
||||||
if (req.user && parseInt(req.user.uid, 10) > 0) {
|
|
||||||
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
|
|
||||||
|
|
||||||
var ws = module.parent.require('./socket.io');
|
|
||||||
ws.logoutUser(req.user.uid);
|
|
||||||
|
|
||||||
req.logout();
|
|
||||||
|
|
||||||
if (master_config.logout_redirect_url){
|
|
||||||
res.redirect(master_config.logout_redirect_url);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
res.redirect("/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log("[sso-saml] Cannot create samlObj");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (samlObj){
|
|
||||||
|
|
||||||
passport.use(samlObj);
|
passport.use(samlObj);
|
||||||
|
|
||||||
strategies.push({
|
strategies.push({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue