passport-local icon indicating copy to clipboard operation
passport-local copied to clipboard

usernameField and passwordField compatible with jsonapi standard.

Open hmontes opened this issue 7 years ago • 4 comments

Hi

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

{
  "data": {
    "type": "user",
    "Attributes": {
      "email": "[email protected]",
      "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)

hmontes avatar Feb 28 '17 20:02 hmontes

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) {

zipper97412 avatar Mar 19 '17 17:03 zipper97412

@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

akoskm avatar Jan 21 '18 19:01 akoskm

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.

philwilks avatar Aug 16 '19 09:08 philwilks

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

mgansler avatar Oct 17 '23 10:10 mgansler