Charrette
Charrette

Reputation: 720

Not getting all profile informations when verifying a google token authenticity

I'm using omniauth on client-side to connect with a google account. Everything is working well, I'm able to get the id_token and some more informations such as the email, name, family_name, given_name etc...

Here is how I configured the provider in app/config/initializer/omniauth.rb :

provider :google_oauth2, ENV['GOOGLE_ID'], ENV['GOOGLE_SECRET'], scope: "profile,email"

Then, as a test, to verify the authenticity of the id_token, using Postman I send a POST request such as:

https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=x

replacing x by the id_token I got on my client

I get a valid answer such as :

{
  "iss": "accounts.google.com",
  "at_hash": "xxx-xxx",
  "aud": "xxx-xxx.apps.googleusercontent.com",
  "sub": "xxx",
  "email_verified": "true",
  "azp": "xxx-xxx.apps.googleusercontent.com",
  "email": "[email protected]",
  "iat": "xxx",
  "exp": "xxx",
  "alg": "xxx",
  "kid": "xxx"
}

When I connected with my client, I allowed the application to access my profile informations and my email, and I've been following this tuto:

https://developers.google.com/identity/sign-in/web/backend-auth

who says :

 // These seven fields are only included when the user has granted the "profile" and
 // "email" OAuth scopes to the application.
 "email": "[email protected]",
 "email_verified": "true",
 "name" : "Test User",
 "picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
 "given_name": "Test",
 "family_name": "User",
 "locale": "en"

I can't figure out why I'm unable to get the 5 last fields

I'm working on an API and I'd like my API to be able to fill a User model by itself, only by getting the id_token. I'm able to get those informations on the client-side but I think this is not the client job to send this extra informations to my API right?

Upvotes: 2

Views: 738

Answers (2)

quest
quest

Reputation: 776

Token calls don't include profile info... for that you muse use:

https://www.googleapis.com/plus/v1/people/me/openIdConnect?access_token=YOUR_ACCESS_TOKEN

Upvotes: 1

Abs
Abs

Reputation: 3962

Since you are doing this with ruby there are 2 things i can suggest trying

  1. Try adding your scopes as an array ["profile", "email"]
  2. Add an extra parameter fetch_basic_profile from here

Upvotes: 0

Related Questions