如何在请求处理函数中处理护照身份验证函数

How to process passport authenticate function in as request handler function

我正在创建一个基于 Node.js 和 Express 4 的 Web 应用程序。我还使用 Passportjs 和 Google OAuth 2 Startegy 进行身份验证。

我正在尝试配置我的路线以处理请求。 我了解到这条线路运行良好:

router.get('/signin/google/callback', passport.authenticate('google', {failureRedirect: '/signin'}));

但是当我决定在函数中处理路由时,应用程序停止响应:

router.get('/signin/google/callback', function (req, res) {
    passport.authenticate('google', {failureRedirect: '/signin'});
});

我错过了什么吗?提前致谢

Google OAuth 函数的回调应该是这样的:

app.get('/auth/google/callback', 
  passport.authenticate('google', { failureRedirect: '/login' }),
  function(req, res) {
    res.redirect('/');
  });

passport.authenticate() 是带有参数 request,response, next 的中间件。您还可以定义自己的中间件或最后一个请求处理程序。