How to get user address and phone number from google auth

不问归期 提交于 2021-01-28 12:16:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!