I hate Google’s APIs… there’s so much undocumented and very little P2P support for this. Like it took 9 months for some one to respond to the original question and now 6 months for an actual answer…
Anyways, I did a bit of research and they have this documentation page for using .tokeninfo().
// Before running the sample:
// - Enable the API at:
// https://console.developers.google.com/apis/api/oauth2.googleapis.com
// - Login into gcloud by running:
// `$ gcloud auth application-default login`
// - Install the npm module by running:
// `$ npm install googleapis`
const {google} = require('googleapis');
const oauth2 = google.oauth2('v2');
async function main() {
const auth = new google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: [],
});
// Acquire an auth client, and bind it to all future calls
const authClient = await auth.getClient();
google.options({auth: authClient});
// Do the magic
const res = await oauth2.tokeninfo({
access_token: 'placeholder-value',
id_token: 'placeholder-value',
});
console.log(res.data);
// Example response
// {
// "audience": "my_audience",
// "email": "my_email",
// "expires_in": 0,
// "issued_to": "my_issued_to",
// "scope": "my_scope",
// "user_id": "my_user_id",
// "verified_email": false
// }
}
main().catch(e => {
console.error(e);
throw e;
});