2017-09-08 45 views
0

我試圖實施的passport.js策略是針對Facebook提供商的策略。我已經測試了教科書示例(從https://github.com/passport/express-4.x-facebook-example),似乎重定向從不被調用。passport.js facebook身份驗證未能正常工作

重定向序列可以正常工作,除非用戶已經登錄,它會重定向到主頁,即使明確地在回調中放入不同的URL。

因此,除了最後一次重定向之外,一切都可以正常工作,最終應該會發生在https://xx.com/testing之間,這絕不會發生。

6的NodeJS,表達4+,護照3.2

到底哪裏出問題了?

戰略

passport.use(new FacebookStrategy({ 
    clientID: xx, 
    clientSecret: 'xx', 
    callbackURL: 'https://xx.com/auth/facebook/callback/', 
    profileFields: ['id', 'email', 'name', 'displayName'] 
}, 
    function (accessToken, refreshToken, profile, done) { 
     return done(null, profile) 
    } 
)) 

路線

router.get('/auth/facebook', passport.authenticate('facebook', {scope: ['public_profile', 'email']})) 
router.get('/auth/facebook/callback', 
    passport.authenticate('facebook', { failureRedirect: '/login' }), 
    function(req, res) { 
    // never gets called 
    console.log('I don't get called!!!') 
    res.redirect('/testing') 
    }) 

回答

1

/testingsuccessRedirect

passport.authenticate('facebook', { 
    successRedirect: '/testing', 
    failureRedirect: '/login' 
})); 

UPDATE:使用passport.authorize

router.get('/auth/facebook/callback', 
    passport.authorize('facebook', { failureRedirect: '/login' }), 
    function(req, res) { 
     res.redirect('/testing') 
    }); 
+0

按預期工作,但我想執行一些代碼,然後重定向。 – Astuanax

相關問題