Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Google API for "googleapis.com/auth/userinfo"

I am developing a Google Chrome Extension. I would like to be able to access the user profile info, using the data from these endpoints:

https://www.googleapis.com/auth/userinfo

https://www.googleapis.com/oauth2/v1/userinfo

I don't seem to have access to these resources. From my web searches, it looks like I may need to enable a library API in the Google Developers Console. But I looked there and cannot find an appropriate API to enable. Does anyone know which API I should enable?

like image 827
Alexander Mills Avatar asked Sep 16 '26 18:09

Alexander Mills


1 Answers

You will need to at least add the scope https://www.googleapis.com/auth/userinfo.profile as per mentioned.

Then you can use the oauth2 apis just like how would you use sheets, calendar etc.

In nodejs, it'd be something like this:

    const { google } = require('googleapis')
    const auth = new google.auth.OAuth2(
      keys.web.client_id,
      keys.web.client_secret,
      keys.web.redirect_uris[0]
    )
    // get the tokens from google
    auth.credentials = tokens
    const oauth2 = google.oauth2({ version: 'v2', auth })
    const userinfo = await oauth2.userinfo.get()
    console.log(userinfo)

The api is documented here: https://googleapis.dev/nodejs/googleapis/latest/oauth2/interfaces/Schema$Userinfo.html#info. There are also some examples in the source code there.

like image 175
Ken H Avatar answered Sep 19 '26 01:09

Ken H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!