jaredhanson / passport-local

Username and password authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-local/?utm_source=github&utm_medium=referral&utm_campaign=passport-local&utm_content=about
MIT License
2.74k stars 498 forks source link

bodyParser #61

Closed gh-naylor closed 10 years ago

gh-naylor commented 10 years ago

"As of express 3.4.0 (connect 2.9.0) bodyParser is deprecated. It goes without saying that deprecated things should be avoided." [1]

Does this fact affect passport-local? I ran across this issue because I'm currently trying to login by sending json in the body via angular/restangular, ie:

{
  email: "test@example.com"
  password: "appleseed"
}

Which makes the question a two-fer... How do I remove bodyParser() and get passport to look for my json body instead of form-data body?

[1] http://andrewkelley.me/post/do-not-use-bodyparser-with-express-js.html

jaredhanson commented 10 years ago

Replace it with:

app.use(express.json());
app.use(express.urlencoded());

That's all bodyParser is (plus multi-part handling), which is typically not needed.

gh-naylor commented 10 years ago

Thanks for the quick reply. I actually tried that but got { name: 'BadRequestError', message: 'Missing credentials' } back inside of passport.authenticate, but as soon as I add bodyParser() back in to my all.js file the error disappears.

jaredhanson commented 10 years ago

I'd double check things and make sure you're on the latest versions.

That's the setup I use, and it works fine. Update the ticket if you pinpoint a problem specifically with this module.

jaredhanson commented 10 years ago

Also note, the request to your server needs to have the correct content-type header set. If it doesn't, the middleware won't parse the body.

gh-naylor commented 10 years ago

Never mind. I was testing in Postman and my angular app at the same time, and my json key was named wrong in my angular app (but correct in Postman).

Simply user error on my part :)

Thanks for the help!