oauthbackendgoogle-signingoogle-authenticationgoogle-auth-library-nodejs

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


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.


Solution

  • 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?