Passport Google oauth2不返回电子邮件。

问题描述 投票:1回答:1

我试图访问用户的详细信息使用护照谷歌oauth2,它返回 id, gender, displayName, name, provider 而不是 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);
    }
  }
));

在配置文件字段中,我已经指定了电子邮件,但它仍然发送所有的东西,除了电子邮件。

这里是get请求,我试图获得认证。

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');
});
authentication passport.js passport-google-oauth2
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.