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

Consider excluding options from authenticate middleware #691

Open
alexandradeas opened this issue Sep 4, 2018 · 2 comments
Open

Consider excluding options from authenticate middleware #691

alexandradeas opened this issue Sep 4, 2018 · 2 comments

Comments

@alexandradeas
Copy link

alexandradeas commented Sep 4, 2018

This issue has arisen mostly out of incorrect implementation anyway but thought I would bring it to attention.

It's possible to inadvertently require authentication on a call to OPTIONS with:

app.use(passport.authenticate("jwt", { session: false })

It's worth pointing out that nowhere in the documentation is the method used in this way.

This can easily be worked around by wrapping the middleware as

app.use((req, res, next) => {
  if (req.method !== "OPTIONS") {
    passport.authenticate("jwt", { session: false });
  }
  next();
});

I'm wondering if it's worth dropping this validation down into passport itself so that it will never require authentication on a call with the OPTIONS method as request headers should not be included according to the standard: https://www.w3.org/TR/cors/#preflight-request

@GlennMatthys
Copy link

Instead of app.use(), use app.get()/app.post()/... Makes more sense than to hard code this into passport.js

@Ravichandra-C
Copy link

Shouldn't this be mentioned in the documentation?

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

No branches or pull requests

3 participants