我有以下使用passport-google-oauth的Node代码...
app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email'] }));
app.get('/auth/google/callback', function(req,res) {
console.log("callback");
passport.authenticate('google', {
successRedirect : '/signin',
failureRedirect : '/signin'
});
});还有..。
passport.serializeUser(function(user, done) {
console.log("ser");
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
console.log("des");
User.findById(id, function(err, user) {
done(err, user);
});
});
passport.use(new GoogleStrategy({
clientID : 'id',
clientSecret : 'key',
callbackURL : 'http://host/auth/google/callback',
},
function(token, rtoken, profile, done) {
console.log("proc");
console.log(profile);
done(null, profile);
}));问题是,回调被调用了,但没有其他事情发生。处理函数从不命中。回调以超时结束。你知道我哪里出错了吗?
发布于 2015-03-30 20:36:01
我刚刚发现passport-google-oauth包导出了以下内容:
exports.Strategy =
exports.OAuthStrategy = OAuthStrategy;
exports.OAuth2Strategy = OAuth2Strategy;这意味着,“默认”(即.策略)根本不是oauth2 ...所以你最好显式地使用OAuth2Strategy。这对我很管用。我花了几个小时才发现这就是问题所在...
发布于 2018-04-24 07:48:19
您没有在第二个路由'/auth/google/callback‘中使用"passport.authenticate('google')“中间件。
您的第二个路由应该如下所示:
app.get( '/auth/google/callback',
passport.authenticate( 'google', {
successRedirect: '/',
failureRedirect: '/login'
}));
https://stackoverflow.com/questions/26219121
复制相似问题