How to get first name and profile picture from id token google sign in

3.2k Views Asked by At

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": "[email protected]",
  "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

There are 2 best solutions below

1
On BEST ANSWER
0
On

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: