2

so I'm making the integration with google sign in from a web-site, so basically the flow here is: google sign in -> get the token id and send to an auth rest api -> rest api get the user Name, profile picture and email then signup the user. My problem is that I'm not beeing able to discover how to get the user name and profile picture. Even with the userinfo.email & userinfo.profile scopes, the token id only stores in the payload the UserId and the email. Here is what my token id payload is looking now:

{ 
  "iss": "accounts.google.com",
  "azp": "######",
  "aud": "######",
  "sub": "######",
  "email": "gsalomaoc@gmail.com",
  "email_verified": true,
  "iat": 1639009337,
  "exp": 1639012937,
  "jti": "######"
}

I was expecting the profile picture and the first&last name to bee sent at the payload. Can any one give me a hand to figure out how to get this fields?

Appreciate any help.

2 Answers2

1

You can use this: www.googleapis.com/oauth2/v1/userinfo

instead of: oauth2.googleapis.com/tokeninfo

Try it out: https://developers.google.com/oauthplayground/

Source: How to get user profile picture from Google Chat Bot using Google App Script?

Diego
  • 326
  • 5
  • 13
  • 1
    Thanks mate, after all, the problem was in the way I was generating the oAuth token. Using google playgroud I was able to generate a good token, that contained the information that I needed. – Gabriel Cunha Dec 27 '21 at 17:24
0

There is really a mess in google oauth/sign-in doc, many scopes are duplicated (e.g. you can use email but also https://www.googleapis.com/auth/userinfo.email who may know if is there some difference?), there are many different end points doing the same but some a little something different e.g. when you have access code from user authorization, you can request :

... result is similar but in doc not explained differences. In my case I could not get user name directly in id_token because I was using https://accounts.google.com/o/oauth2/token and when switched to https://oauth2.googleapis.com/token id_token contains now more items including name! I think this may help someone else too.

Useful links:

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mikep
  • 5,880
  • 2
  • 30
  • 37