Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data can I save in my database to verify a user with Google sign in API?

I need to store data related to a (Google) user in my database. I tried to store the id_token, but later found out that the part after the '.' changed. What can be used instead, or can I just save the part infront of the "." from the id_token?

like image 446
ntoonio Avatar asked May 02 '16 18:05

ntoonio


People also ask

What data can I get from Google login?

After you have signed in a user with Google using the default scopes, you can access the user's Google ID, name, profile URL, and email address.

What term can we use to fetch results for login pages on Google?

Once Google discovers a page's URL, it may visit (or "crawl") the page to find out what's on it. We use a huge set of computers to crawl billions of pages on the web. The program that does the fetching is called Googlebot (also known as a robot, bot, or spider).


1 Answers

Thanks Steven Soneff

Use the 'sub' field of the ID token, it is invariant for the Google user https://developers.google.com/identity/sign-in/android/backend-auth#calling-the-tokeninfo-endpoint

The ID token have three parts; the header, body and signature, divided by a '.' (header.body.signature). Each part is encoded with base64. If you decode the body, you will get a JSON like this:

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

...you can safely retrieve and use the user's unique Google ID from the sub claim

So you can save the sub in your database to identify your user

like image 97
ntoonio Avatar answered Oct 15 '22 10:10

ntoonio