0

我創建基於Node.js和受快遞4.我也使用Passportjs和谷歌的OAuth 2 Startegy用於驗證的Web應用程序的護照身份驗證功能。如何爲請求處理功能

我想配置,以處理請求我的路線。 我已經瞭解到,該行正常工作:

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

但是當我決定來處理功能的路由,應用程序停止響應:

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

難道我錯過了什麼?在此先感謝

回答

1

在谷歌的OAuth功能的回調應該是這樣的:

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

passport.authenticate()是中間件參數request,response, next。您也可以定義自己的中間件或最後一個請求處理程序。