我在一个ExpressJS web应用中使用PassportJS和passport-google-oauth。
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: CALLBACK
},
function(accessToken, refreshToken, profile, done) {
console.log(profile.displayName);
console.log(profile.name.familyName);
console.log(profile.name.givenName);
...
}));问题是profile.displayName、profile.name.familyName和profile.name.givenName都是未定义的。当我在Passport Facebook中使用回调时,完全没有问题。
如何在使用Google帐号登录时获取用户名?
发布于 2015-10-23 14:57:31
当我检查时,它似乎有比官方样本中的参数更多的参数,导致包括我在内的人们感到困惑。
而不是
function(accessToken, refreshToken, profile, done)使用
function(req, accessToken, refreshToken, profile, done)发布于 2013-11-16 17:00:33
您需要请求它,将'https://www.googleapis.com/auth/userinfo.profile'包含在您的作用域中。
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: CALLBACK,
scope: ['https://www.googleapis.com/auth/userinfo.profile','email', ...]
}https://stackoverflow.com/questions/17399635
复制相似问题