参数化护照社交登录回调

时间:2017-02-24 14:05:32

标签: node.js facebook passport.js

我对facebook和linkedin回调有以下回调:

router.get('/auth/linkedin/callback', social.linkedin().authenticate('linkedin', {failureRedirect: '/web/login'}), function(req, res, next) { res.redirect(req.session.redirectURL); });
router.get('/auth/facebook/callback', social.facebook().authenticate('facebook', {failureRedirect: '/web/login'}), function(req, res, next) { res.redirect(req.session.redirectURL); });

如何对它们进行参数化以便我可以取消一个衬垫,比如说

// somehow get a service from the wildcard in the uri    
router.get('/auth/*/callback', social.service().authenticate(service, {failureRedirect: '/web/login'}), function(req, res, next) { res.redirect(req.session.redirectURL); });

1 个答案:

答案 0 :(得分:0)

试试这个

router.get('/auth/:service/callback', function (req, res, next) {
    social[req.params.service]().authenticate(req.params.service, {failureRedirect : '/web/login'})(req, res, next);
}, function (req, res, next) {
    res.redirect(req.session.redirectURL);
});