Logging out using passport-saml: req.logout() or Strategy.logout(), or both?

為{幸葍}努か 提交于 2019-11-30 09:46:58

Yes adding the nameIDFormat and nameID to the user will solve the issue.

  1. To enable the logout you should configure the logoutURL option in your strategy

logoutUrl: 'http://example.org/simplesaml/saml2/idp/SingleLogoutService.php',

The logout method in the strategy does not actually send any request. the callback function is called with the request as parameter.

To launch the logout process :

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);
        }
    });
};

edit: the nameId and nameIdFormat has to be saved somewhere on successful login

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

      });
  });
  1. You will also have to create an end point for the logout callback :

This URL should be configured in your SP metadata in your IdP configuration. The IdP will redirect to that URL once the logout is done.

in your routes :

app.post('/auth/saml/logout/callback', passport.logoutSamlCallback);

In your passport configuration :

passport.logoutSamlCallback = function(req, res){
    req.logout();
    res.redirect('/');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!