2

我正在尝试使用护照谷歌 oauth2 访问用户详细信息,它返回id, gender, displayName, nameprovider但不是email

passport.use(new GoogleStrategy({
  clientID: '1050835058852-cmniek05f0tdotj4ikp54s8qvvgbd9j4.apps.googleusercontent.com',
  clientSecret: 'LjnSZOwA95bL6hvKMYjWPc_Q',
  callbackURL: 'http://localhost:3000/auth/google/callback',
  profileFields: ['id', 'email', 'gender', 'displayName', 'name', 'provider']
},
function(accessToken, refreshToken, profile, cb) {
    if (profile) {
        user = profile;
        console.log(profile);
        passport.serializeUser(function(user, done) {
            done(null, user);
        });
        passport.deserializeUser(function(user, done) {
            done(null, user);
        });
        return cb(null, user);
    }
    else {
        return cb(null, false);
    }
  }
));

在我指定了电子邮件的配置文件字段中,它仍然发送除电子邮件之外的所有内容。

这是我试图通过身份验证的获取请求。

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

app.get('/auth/google/callback',
  passport.authenticate('google', { failureRedirect: '/auth/google' }),
  function(req, res) {
  // Successful authentication, redirect home.
  res.redirect('/account');
});
4

0 回答 0