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

usernameField and passwordField compatible with jsonapi standard. #153

Open
hmontes opened this issue Feb 28, 2017 · 4 comments
Open

usernameField and passwordField compatible with jsonapi standard. #153

hmontes opened this issue Feb 28, 2017 · 4 comments

Comments

@hmontes
Copy link

hmontes commented Feb 28, 2017

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
Copy link

zipper97412 commented Mar 19, 2017

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
Copy link

akoskm commented Jan 21, 2018

@zipper97412 many thanks! Looking at the lookup functions this is how it works:

var chain = field.split(']').join('').split('[');

@philwilks
Copy link

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
Copy link

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

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

5 participants