How to authenticate with node.js Passport through a get-request?


I am using 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:'/login', 
    passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),
    function(req, res) {

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?

Problem courtesy of: mritz_p


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:

Solution courtesy of: hunmonk


Maybe 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");

Discussion courtesy of: Rax Wunter

This recipe can be found in it's original form on Stack Over Flow.