问题
Iam using passport.js for authentication using passport-google-oauth20,
I was wondering how can get user information like address, phone number ? so far i just can get information like email, name, profile but not address and phone number. how can access user data address after login with google ?
Is there any API to access this user address and phone number ? what should I do ?
this is my code :
Passport setup
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);
})
);
Route
routes.get('/auth/google',passport.authenticate("google",{
scope: ["profile", "email"]
}));
回答1:
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'
]
}));
this returns the user data
来源:https://stackoverflow.com/questions/55661952/how-to-get-user-address-and-phone-number-from-google-auth