How to authenticate using node.js Passport through a request for receipt?

I am using Passport-Local (https://github.com/jaredhanson/passport-local) to authenticate with node.js. So far, this example works like a charm, as users register on the post-webform blog:

app.post('/login', 
    passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),
    function(req, res) {
        res.redirect('/');
});

Now, however, I want to copy the JSON-based API to authenticate users by calling a specific URL. However, changing the code code to app.get(…does not work.

Any tips?

+3
source share
2 answers

I ran into the same problem and solved it by adding this to my route handler for entry:

req.body = req.query;

Perhaps this is not an ideal solution, but it is certainly better than hacking a passport.;)

, -local: https://github.com/jaredhanson/passport-local/pull/12

+2

https://github.com/yarax/passport-url

GET

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);
0

All Articles