title: how do I redirect back to the originally-requested url after authentication with passport-saml?
body: <p>Sorry if this is a bonehead question, but I'm having some trouble understanding how I might redirect the client browser back to whatever URL was originally requested after a successful authentication with our SAML identity provider (IdP). I'm using the latest versions of passport-saml, passport, and express.</p>
  
  <p>For example, say the client originally requested <code>/foo/bar</code> from a link on another unprotected page, but since that is a protected resource, I respond with a redirect to <code>/login</code>, which is where I call <code>passport.authenticate('saml')</code>.</p>
  
  <pre><code>app.get('/login', passport.authenticate('saml'));
  
  function ensureAuth(req, res, next) {
      if (req.user.isAuthenticated()) {return next();}
      else {res.redirect('/login');}
  }
  
  app.get('/foo/bar', ensureAuth, function(req, res) {
      ...
  });
  </code></pre>
  
  <p>That call will redirect the browser to my IdP's sign-on page, and after a successful authentication, the IdP POSTs back to my <code>/login/callback</code> route. In that route, I again use <code>passport.authenticate(saml)</code> to validate the response SAML, and if all is good, I then get to redirect the browser back to the requested resource...but how do I know what that requested resource was? Because it's a POST callback, I've lost any state associated with the original request.</p>
  
  <pre><code>app.post('/login/callback', passport.authenticate('saml'), function(req, res) {
      res.redirect('...can I know which url to redirect back to?...');
  });
  </code></pre>
  
  <p>The example in the <a href="https://github.com/bergie/passport-saml/blob/master/README.md">passport-saml readme</a> just shows a hard-coded redirect back to the root resource, but I would want to redirect back to the originally-requested URL (<code>/foo/bar</code>).</p>
  
  <p>Can I send a url, or some other value, to the IdP that will get round-tripped and POSTed back in the response SAML? And if so, how can I access it in my <code>/login/callback</code> route?</p>
  
  <p>Or is there some better, express/passport way to do this that I'm missing?</p>
  
  <p>Any help you can provide would be most appreciated!</p>