1
votes

I'm using passportjs with OAuthStrategy2 from Jared Hanson (https://github.com/jaredhanson/passport-google-oauth). I want to get user age range in profile object but I can't get it. Even if I'm using https://www.googleapis.com/auth/plus.login in a scope, for which google guarantees will return age scope. Is there a way to obtain this info through passport or I'll be forced to make REST request to google past passport?

This is passport authenticate with a scope I'm using:

        app.get('/auth/login/google',
        passport.authenticate('google', {
            scope: ['https://www.googleapis.com/auth/plus.login',
                'https://www.googleapis.com/auth/userinfo.email'
            ]
        }),
        function(req, res) {});

And this is result I got:

{ 
  provider: 'google',
  id: '115346138147341087148',
  displayName: 'Testing Account',
  name: { familyName: 'Account', givenName: 'Testing' },
  emails: [ { value: undefined } ],
  _raw: '{\n "id": "115346138147341087148",\n "name": "Testing Account",\n "given_name":       "Testing",\n "family_name": "Account",\n "link":   "https://plus.google.com/115346138147341087148",\n "picture":   "https://lh3.googleusercontent.com/-  XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",\n "gender": "female",\n "locale": "en"\n}\n',
  _json: 
   { id: '115346138147341087148',
     name: 'Testing Account',
     given_name: 'Testing',
     family_name: 'Account',
     link: 'https://plus.google.com/115346138147341087148',
     picture: 'https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg',
  gender: 'female',
  locale: 'en' } 
}

Thank you all in advance.

1
I suspect your problem is with the project on github its a bit old. It may not support that. I checked people:get does return age range even if it is in my case off by 50% (21 thanks Google)DaImTo

1 Answers

1
votes

As someone pointed out somewhere else (probably Stackoverflow or something similar), it is just not possible to get more info using passport-google. You and I will have to use the official Google API methods to get more info. Unfortunately there is not the option to add profileFields to the strategy to request more info in the response (as it is possible with passport-facebook).