我有一个问题,如何正确地注销一个用户时,使用护照-saml进行身份验证。
带有passport的示例脚本显示了如下所示的注销:
app.get('/logout', function(req, res){
req.logout();
res.redirect('/');
});据我所知,这将结束本地护照会话,但它似乎没有向SAML IdP发送注销请求。当用户执行另一个登录时,它会重定向到IdP,但会立即与经过身份验证的用户重定向。是否有办法使用IdP注销,以便用户在登录到我的站点时必须再次输入密码?我见过其他使用我们的IdP的网站会这么做,所以我认为这是可能的。
我确实注意到在passport代码中有一个logout()方法在passport对象上,这个方法似乎没有被req.logout()调用。所以我试着把代码转换成这样:
app.get('/logout', function(req, res) {
//strategy is a ref to passport-saml Strategy instance
strategy.logout(req, function(){
req.logout();
res.redirect('/');
});
});但是我在XMLNode.js中发现了这个错误
Error: Could not create any elements with: [object Object]
at XMLElement.module.exports.XMLNode.element (/.../node_modules/passport-saml/node_modules/xmlbuilder/lib/XMLNode.js:74:15)
at XMLElement.module.exports.XMLNode.element (/.../node_modules/passport-saml/node_modules/xmlbuilder/lib/XMLNode.js:54:25)
at XMLElement.module.exports.XMLNode.element (/.../node_modules/passport-saml/node_modules/xmlbuilder/lib/XMLNode.js:54:25)
at new XMLBuilder (/.../node_modules/passport-saml/node_modules/xmlbuilder/lib/XMLBuilder.js:27:19)
at Object.module.exports.create (/.../node_modules/passport-saml/node_modules/xmlbuilder/lib/index.js:11:12)
at SAML.generateLogoutRequest (/.../node_modules/passport-saml/lib/passport-saml/saml.js:169:21)我是不是没有正确地调用这个方法?或者我不应该直接调用此方法,而是调用其他方法?
我看到,在generateLogoutRequest()中,它指的是req.user上的两个属性,我不确定它们是否存在:
'saml:NameID' : {
'@Format': req.user.nameIDFormat,
'#text': req.user.nameID
}如果这些属性不存在,这会导致这个错误吗?如果是这样的话,我假设可能需要确保将这些属性添加到从验证回调函数返回的用户对象中?
感谢任何人能在这方面提供的任何帮助。
发布于 2014-09-28 08:38:13
是的,向用户添加nameIDFormat和nameID将解决这个问题。
logoutUrl: 'http://example.org/simplesaml/saml2/idp/SingleLogoutService.php',
策略中的注销方法实际上不会发送任何请求。调用回调函数时,请求作为参数。
启动注销进程:
passport.logoutSaml = function(req, res) {
//Here add the nameID and nameIDFormat to the user if you stored it someplace.
req.user.nameID = req.user.saml.nameID;
req.user.nameIDFormat = req.user.saml.nameIDFormat;
samlStrategy.logout(req, function(err, request){
if(!err){
//redirect to the IdP Logout URL
res.redirect(request);
}
});
};编辑: nameId和nameIdFormat必须在成功登录时保存在某个地方。
var samlStrategy = new SamlStrategy(
{
callbackUrl: 'https://mydomain/auth/saml/callback',
entryPoint: 'https://authprovider/endpoint',
logoutUrl: 'https://authprovider/logoutEndPoint',
issuer: 'passport-saml'
},
function(profile, done) {
//Here save the nameId and nameIDFormat somewhere
user.saml = {};
user.saml.nameID = profile.nameID;
user.saml.nameIDFormat = profile.nameIDFormat;
//Do save
});
});这个URL应该在IdP配置中的SP元数据中配置。一旦注销完成,IdP将重定向到该URL。
在你的路线上:
app.post('/auth/saml/logout/callback', passport.logoutSamlCallback);在您的护照配置中:
passport.logoutSamlCallback = function(req, res){
req.logout();
res.redirect('/');
}https://stackoverflow.com/questions/25271072
复制相似问题