title: Passport-SAML: read user information
body: <p>Still a noob!</p>
  
  <p>I am working on to build a Node application, and I have already setup various required end points. One of the requirements for my project is to use authentication using SAML mechanism. I am using passport-SAML for authentication in my application. </p>
  
  <p>So far, I have been able to setup and use SAML strategy, and my application is able to call the idp entry point, and receive the response back from Idp. </p>
  
  <p>I am unable to understand how do we access the user information returned by idp, so that I can use the SAML returned user information to create and maintain sessions. </p>
  
  <pre><code>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 -&gt; Service Provider
        callbackUrl: config.passport.saml.callback_url,
        // path: config.passport.saml.path,
        // URL that goes from the Service Provider -&gt; 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);
  
  };
  </code></pre>
  
  <p>Following are my route controllers for express</p>
  
  <pre><code>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('/');
      }
  );
  </code></pre>
  
  <p>And this is a SAML snippet of properties that I recieve in response from Idp.</p>
  
  <pre><code>&lt;saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"&gt;Shubham123&lt;/saml:NameID&gt;
  </code></pre>