Closed meepeek closed 10 years ago
I think what you do is this:
passport.use(new LocalStrategy({
usernameField: 'username',
passwordField: 'password'
},
function(username, password, done) {
// ...
}
));
As long as the json you post from angularjs is something like: {username: 'xxxxxxx', password: 'xxxxxxx'}
that should work according to https://github.com/jaredhanson/passport-local/blob/master/lib/strategy.js#L71
I have the same issue (also using Angular.js). It is impossible to use the username and password from json if it is nested, say:
POST /api/users/login
{
user: {
email: '936@xkcd.com',
password: 'correct horse battery staple'
}
}
I've tried setting usernameField
to user.email
and passwordField
to user.password
, but that didn't work. I'll try messing with the lib/utils.js lookup function.
Alternatively, maybe allow us to override the object passed to Strategy.authenticate? In my case, it would be something like:
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password',
object: req.body.user
},
function(username, password, done) {
// ...
}
));
It takes a form-style notation for nesting:
passport.use(new LocalStrategy({
usernameField: 'user[email]',
passwordField: 'user[password]',
object: req.body.user
},
function(username, password, done) {
// ...
}
));
Thanks!
From the piece of the code that was given for an example in passportjs documentation
passport.use(new LocalStrategy( function(username, password, done) {
I finally realise that PassportJS try to automatically get the username / password field in the post request automatically but the problem is that I am using angularjs and ajax to do the submission so my post request for the login would be just a json object contains information scraped from the login form. Is there any option to manually pass the username and password directly as variable ?