As already mentioned, you can send GET to https://www.googleapis.com/oauth2/v1/userinfo using the OAuth2 token you just received and you will get a response with some information about the user (id, name etc.).
It is also worth mentioning that Google implements OpenID Connect and that this endpoint of user information is only part of it.
OpenID Connect is an authentication layer on top of OAuth2. When exchanging code authorization on the endpoint of a Google token, you get an access token ( access_token parameter), as well as an OpenID Connect identifier token ( id_token parameter).
Both of these are JWT tokens (JSON Web Token, http://tools.ietf.org/html/draft-ietf-oauth-json-web-token ).
If you decode them, you will get some statements, including the user id . If you associate this identifier with a user in your database, you can immediately identify them without performing an additional user GET (saves time).
As mentioned in the comments, these tokens are signed with the Google private key, and you can verify the signature with the Google public key ( https://www.googleapis.com/oauth2/v1/certs ) to make sure they are genuine.
You can see that in JWT by inserting it into https://jwt.io/ (scroll down for the JWT debugger). The statements look something like this:
{ "iss":"accounts.google.com", "id":"1625346125341653", "cid":"8932346534566-hoaf42fgdfgie1lm5nnl5675g7f167ovk8.apps.googleusercontent.com", "aud":"8932346534566-hoaf42fgdfgie1lm5nnl5675g7f167ovk8.apps.googleusercontent.com", "token_hash":"WQfLjdG1mDJHgJutmkjhKDCdA", "iat":1567923785, "exp":1350926995 }
There are also libraries for various programming languages ββfor JWT software decoding.
Christophe L 22 Oct. '12 at 16:56 2012-10-22 16:56
source share