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.73k stars 497 forks source link

usernameField and passwordField compatible with jsonapi standard. #153

Open hmontes opened 7 years ago

hmontes commented 7 years ago

Hi

According to jsonapi (http://jsonapi.org/). I send this json to login in my api server:

{
  "data": {
    "type": "user",
    "Attributes": {
      "email": "example@example.com",
      "password": "thepasskey"
    }
  }
}

How can i put this in userField and passwordField? (the example don't work)

passport.use(new LocalStrategy(
  {
    usernameField: 'data.Attributes.email',
    passwordField: 'data.Attributes.password'
  },
  function(email, password, done) {

Thanks :)

(Jsonapi is an STANDARD)

zipper97412 commented 7 years ago

Replace '.' with '[]' to access nested object, I think there is a bug in lookup function

passport.use(new LocalStrategy(
  {
    usernameField: 'data[]Attributes[]email',
    passwordField: 'data[]Attributes[]password'
  },
  function(email, password, done) {
akoskm commented 6 years ago

@zipper97412 many thanks! Looking at the lookup functions this is how it works: https://github.com/jaredhanson/passport-local/blob/3b9980f6467fd1203ecf8844fb017b5db2941606/lib/utils.js#L3

philwilks commented 5 years ago

Have you considered using the passport-custom strategy instead? It is even more stripped back than passport-local, and makes no assumptions about how you are passing in the email and password.

So for example you can read them from a JSON post as in your JSON:API example.

mgansler commented 10 months ago

I think the supposed way to provide a nested field is usernameField: 'data[Attributes][email]' which results in a "chain" of ['data', 'Attributes', 'email']