如何从Google auth获取用户地址和电话号码 [英] How to get user address and phone number from google auth
本文介绍了如何从Google auth获取用户地址和电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用passport.js通过Passport-google-oauth20进行身份验证,
我想知道怎样才能获得地址、电话号码等用户信息?到目前为止,我只能获得电子邮件、姓名、个人资料等信息,但不能获得地址和电话号码。登录Google后如何访问用户数据地址?
是否有API可以访问此用户地址和电话号码?我该怎么办?
这是我的代码:
护照设置
passport.use(
new GoogleStrategy({
//options for the google strategy
callbackURL: keys.origin.url + '/api/auth/google/redirect',
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret,
userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
}, (accessToken, refreshToken, profile, done) => {
console.log(profile);
})
);
路由
routes.get('/auth/google',passport.authenticate("google",{
scope: ["profile", "email"]
}));
推荐答案
routes.get('/auth/google',passport.authenticate("google",{
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/user.phonenumbers.read',
'https://www.googleapis.com/auth/user.addresses.read',
'https://www.googleapis.com/auth/profile.agerange.read'
]
}));
这将返回用户数据
这篇关于如何从Google auth获取用户地址和电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文