I am using Passport-Local (https://github.com/jaredhanson/passport-local) to authenticate with node.js. So far this example works like a charm, since the users are logging in thorugh a post-webform:
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),
function(req, res) {
res.redirect('/');
});
Now, however, I want to code up a JSON-based API to authenticate users by calling a particular URL. Modifying the code block to app.get(… doesn’t work though.
Any advice?
I ran into this same problem, and solved it by adding this to my route handler for login:
Maybe not the perfect solution, but it’s certainly better than hacking passport. 😉
Also note that there’s a pending request in passport-local to fix this problem: https://github.com/jaredhanson/passport-local/pull/12