Passport-SAML:读取用户信息

还是小菜一碟!

我正在构build一个Node应用程序,并且我已经设置了各种所需的端点。 我的项目的一个要求是使用SAML机制进行身份validation。 我在我的应用程序中使用passport-SAML进行身份validation。

到目前为止,我已经能够设置和使用SAML策略,我的应用程序可以调用idp入口点,并从Idp接收回应。

我无法理解我们如何访问由idp返回的用户信息,以便我可以使用SAML返回的用户信息来创build和维护会话。

const saml = require('passport-saml'); module.exports = function (passport, config) { passport.serializeUser(function (user, done) { done(null, user); }); passport.deserializeUser(function (user, done) { done(null, user); }); var samlStrategyOptions = new saml.Strategy( { // URL that goes from the Identity Provider -> Service Provider callbackUrl: config.passport.saml.callback_url, // path: config.passport.saml.path, // URL that goes from the Service Provider -> Identity Provider entryPoint: config.passport.saml.entryPoint, issuer: config.passport.saml.issuer, identifierFormat: null, // Service Provider private key decryptionPvk: config.passport.saml.decryptionPvk, // Service Provider Certificate privateCert: config.passport.saml.privateCert, // Identity Provider's public key cert: config.passport.saml.cert, validateInResponseTo: false, disableRequestedAuthnContext: true }, function (profile, done) { return done(null, { id: profile.uid, email: profile.email, displayName: profile.cn, firstName: profile.givenName, lastName: profile.sn }); }) // module.exports.samlStrategyOptions = samlStrategyOptions ; passport.use(samlStrategyOptions); }; 

以下是我的快递路线控制器

 router.route('/login') .get( passport.authenticate(config.passport.strategy, { successRedirect: '/', failureRedirect: '/login' }) ); router.route('/login/callback/') .post( passport.authenticate(config.passport.strategy, { failureRedirect: '/', failureFlash: true }), function (req, res) { res.redirect('/'); } ); 

这是我从Idp收到的一个SAML的属性片段。

 <saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">Shubham123</saml:NameID>