我正在Node中使用Passport-SAML通过SAML对用户进行身份验证。我想使用generateServiceProviderMetadata(decryptionCert)生成SP元数据,我可以在Passport中完成此操作,但是我很难从Express中调用它。我似乎已经尝试了一切,希望能得到帮助。
Passport.js
var passport = require('passport');
var SamlStrategy = require('passport-saml').Strategy;
var fs = require('fs');
var samlConfig = {
issuer: 'http://localhost:3021/api/v1/users/metadata',
callbackUrl: 'http://localhost:3021/api/v1/users/login/callback',
path: '/api/v1/users/login/callback',
decryptionCert: fs.readFileSync('./config/certificate.crt', 'utf-8'),
decryptionPvk: fs.readFileSync('./config/mykey.key', 'utf-8'),
entryPoint: 'https://okta-entryPoint.com',
cert: fs.readFileSync('./config/okta.cert', 'utf-8')
};
var saml_strategy = new SamlStrategy(samlConfig,
function(profile, done) {
console.log(profile.nameID, 'SAML Succesful');
if (!profile.nameID) return done(new Error("No email found"), null);
User.findOne({username: profile.nameID}, function(err, user) {
// console.log(user, 'Checking user in Database');
if(err) return done(err);
if(user) return done(null, user);
if(!user) return done(null, profile);
});
}
);
function samlEntity(){
var decryptionCert = fs.readFileSync('./config/certificate.crt', 'utf-8');
return saml_strategy.generateServiceProviderMetadata(decryptionCert);
}
// console.log(samlEntity(), "samlEntity");
passport.use('samlEntity', samlEntity());
passport.use("saml_strategy", saml_strategy);
Express.js
passport.authenticate('samlEntity', function(err, metadata) {
console.log(metadata, 'samlEntity in routes');
})(req, res, next);