The passport.js strategy that I am trying to implement is the one for the facebook provider. I have tested with the text book example (from https://github.com/passport/express-4.x-facebook-example ) and it seems the redirect is never called.
The redirect sequence works fine except when the user is logged in, it redirects to the homepage, even when explicitly putting a different URL in the callback.
So everything works except the last redirect, which should end up at https://xx.com/testing which never happens.
nodejs 6, express 4+, passport 3.2
What is going wrong?
Strategy
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)
}
))
Route
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')
})
/testing
goes to successRedirect
passport.authenticate('facebook', {
successRedirect: '/testing',
failureRedirect: '/login'
}));
UPDATE: Use passport.authorize
router.get('/auth/facebook/callback',
passport.authorize('facebook', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/testing')
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.