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:
req.body = req.query;
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
Maybe https://github.com/yarax/passport-url strategy will be useful for you
It allows to authenticate users with a token giving by GET request
var url = new UrlStrategy({
failRedirect : "/login",
varName : "secret"
}, function (secret, done) { // put your check logic here
if (secret == 'foo') done(null, {id:'bar'});
else done("wrong");
});
passport.use(url);