是的,将 nameIDFormat 和 nameID 添加到用户将解决该问题。
- 要启用注销,您应该在策略中配置 logoutURL 选项
logoutUrl: 'http://example.org/simplesaml/saml2/idp/SingleLogoutService.php',
策略中的logout方法实际上并不发送任何请求。以请求作为参数调用回调函数。
要启动注销过程:
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 和 nameId 格式必须在成功登录后保存在某处
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
});
});
- 您还必须为注销回调创建一个端点:
应在 IdP 配置的 SP 元数据中配置此 URL。注销完成后,IdP 将重定向到该 URL。
在你的路线中:
app.post('/auth/saml/logout/callback', passport.logoutSamlCallback);
在您的护照配置中:
passport.logoutSamlCallback = function(req, res){
req.logout();
res.redirect('/');
}