I want to get the birthday of an user using Passport.js with the passport-google-oauth20
strategy. Where do I get the response of this extra scope and how do I extract this information?
I am having success on extracting the profile and email from an user, but every other scope I try I cannot seem to find where it returns. I'm using some scopes from Google Identity Platform (more specifically People API, which I already activated from Google Cloud Platform) and they do not appear in the Passport strategy callback (only profile and email).
This is where I setup passport and check what is returning
passport.use(
new GoogleStrategy(config, (accessToken, refreshToken, profile, done) => {
console.log(profile);
// outputs:
// id: ...
// displayName: ...
// name: { ... }
// emails: [ { ... } ]
// photos: [ { ... } ]
// _raw: ...
// _json: ... (above info plus profile link and locale)
...
})
);
Inside my routes I declare the scopes and redirect the user
router.get('/auth/google/', passport.authenticate('google', {
scope: ['https://www.googleapis.com/auth/user.birthday.read', 'profile', 'email']
}));
router.get('/auth/google/redirect/', passport.authenticate('google'), (req, res) => {
res.redirect('http://localhost:2000/profile/' + req.user.id)
})
My node and npm versions currently are:
node --version
v8.12.0
npm --version
6.9.0
And my package versions are the following:
...
"express": "^4.16.4",
"passport": "^0.4.0",
"passport-google-oauth20": "^2.0.0",
...
From what I understand, I should be able to retrieve more information other than profile, email and openid with Passport and I understand that I need to get the API of the scope I want activated. What I do not understand is how to retrieve the info from that API in the callback function or how to retrieve that info at all.