谷歌oauth不返回电子邮件通行证authentication

我正在尝试使用节点js的护照模块使用Googlebutton进行login。 我想获得人员的电子邮件ID,名称,个人资料图片。 我正试图下载图片到本地服务器。 即使向作用域添加“电子邮件”,Google也不会返回电子邮件地址,也不会返回用于个人资料图片的链接。 我已经看了这个问题的各种答案,但都说包括userinfo.email。现在已被弃用。 根据谷歌文档新的范围参数是电子邮件下面是我的代码任何帮助赞赏护照

passport.use(new GoogleStrategy({ clientID : configAuth.googleAuth.clientID, clientSecret : configAuth.googleAuth.clientSecret, callbackURL : configAuth.googleAuth.callbackURL, }, function(token, refreshToken, profile, done) { // make the code asynchronous // User.findOne won't fire until we have all our data back from Google process.nextTick(function() { // try to find the user based on their google id User.findOne({ 'google.id' : profile.id }, function(err, user) { if (err) return done(err); if (user) { // if a user is found, log them in return done(null, user); } else { // if the user isnt in our database, create a new user var newUser = new User(); console.log(profile); //JSON.parse(profile); // set all of the relevant information newUser.google.id = profile.id; newUser.google.token = profile.token; newUser.google.name = profile.displayName; newUser.google.uname = profile.emails[0].value; // pull the first email newUser.google.dp = profile._json.picture; console.log('url is'); console.log(newUser.google.name); console.log(newUser.google.dp); //console.log(profile.picture); Download(newUser.google.uname, newUser.google.dp,function(err){ if(err) console.log('error in dp'); else console.log('Profile Picture downloaded'); }); // save the user newUser.save(function(err) { if (err) throw err; return done(null, newUser); }); } }); }); })); }; 

routes.js

  app.get('/connect/google', passport.authorize('google', { scope : ['profile', 'email'] })); // the callback after google has authorized the user app.get('/connect/google/callback', passport.authorize('google', { successRedirect : '/profile', failureRedirect : '/' })); 

download.js

  module.exports = function(username, uri, callback){ var destination; request(uri).pipe(fs.createWriteStream("./downloads/"+username+".png")) .on('close', function(){ console.log("saving process is done!"); }); 

我有同样的问题,并以这种方式写了范围:

 app.get('/connect/google', passport.authenticate('google', { scope: [ 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email' ] })); 

你会得到电子邮件:

 function(accessToken, refreshToken, profile, done) { console.log(profile.emails[0].value); }); 

我希望这可以帮助你。

上面的答案肯定有效,还有一种方法可以解决这个问题。

 app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }) ); 

在您的routes.jsprofile添加email

这应该可以解决你的问题。