2016-07-15 88 views
0

第一次使用护照,我意识到当我在策略回调中记录数据时,它不会显示在控制台中,它是如何工作的,还是我做错了什么?Passport Not calling callback

passport.use(new GoogleStrategy({ 
    clientID: process.env.GOOGLE_CLIENT_ID, 
    clientSecret: process.env.GOOGLE_CLIENT_SECRET, 
    callbackURL: process.env.CALLBACK_URL, 
    passReqToCallback: true 
}, function (accessToken, refreshToken, profile, done) { 
    console.log('this should be displayed'); 
    done(profile) 
    } 
); 

路线是这样的:

app.get('/api/v1/authenticate/google', passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/plus.login'] })); 

回答

1

我有同样的问题,并通过调用类似这样的认证解决它:

passport.authenticate('facebook', { 
    scope: ['email', 'public_profile', 'user_likes', 'user_birthday'], 
    callbackURL: "http://localhost:1337" + req.url 
}, function (err, user) { 
    if (err) return res.negotiate(err); 
    // Do something 
})(req, res, next); 
-1

如果设置passReqToCallback:true,你的回调会被调用以req作为第一个参数。

你应该叫它为 function (req, accessToken, refreshToken, profile, done), 所以done将在正确的位置。编辑: 我意识到你的意思是主要回调。 这是一个两步过程,因此process.env.CALLBACK_URL也应指向注册护照中间件的路由。

从文档:

如果callbackURL: "http://yourdormain:3000/auth/google/callback",

app.get('/auth/google/callback', 
    passport.authenticate('google', { 
     successRedirect: '/auth/google/success', 
     failureRedirect: '/auth/google/failure' 
})); 
相关问题