Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep reference to original requested url #108

Open
zabakala opened this issue Oct 26, 2018 · 2 comments
Open

keep reference to original requested url #108

zabakala opened this issue Oct 26, 2018 · 2 comments
Labels

Comments

@zabakala
Copy link

zabakala commented Oct 26, 2018

Following the example of this repo, what is the proper way of keeping a reference to the original requested url? This information is available in the former request as req.originalUrl but it gets lost if the user is not authenticated and the redirection (from GET /login to POST /login etc.) and authentication take place. The example in this repo has a static /

I tried to relay a state. Something like:

req.query.RelayState = req.params.redirect_to;
passport.authenticate('saml')(req, res, next);

... but to no avail. The information still gets lost.

@machuga
Copy link
Contributor

machuga commented Oct 26, 2018

Hi @davidgithub1980! Since the request data won't be available after redirect, have you considered storing them in a cookie or session storage?

@Jarlotee
Copy link

Jarlotee commented Nov 7, 2018

@davidgithub1980 I had the same question here is what I did

const redirect_cookie = 'redirect-cookie';

app.use((req, res, next) => {
      if (!req.isAuthenticated()) {
        res.cookie(redirect_cookie, req.path);
        res.redirect('/login');
      } else {
        next();
      }
    });

 app.post('/login/callback', passport.authenticate('wsfed-saml2'), (req, res) => {
    if (req.cookies && req.cookies[redirect_cookie]) {
      res.clearCookie(redirect_cookie);
      res.redirect(req.cookies[redirect_cookie]);
    } else {
      res.redirect('/');
    }
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants