Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sign-In endpoint doesn't return the user's name anymore

I'm using Google Sign-In on my iOS app. Everything was working well until recently when I noticed the app no longer gets the user's name, only the email address is returned.

I am getting a token through the app that I am sending to my server, which used to fetch the full information by sending a request to this endpoint:

https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=MYTOKEN

I'm getting this kind of answer now:

{

    "issuer": "https://accounts.google.com",
    "issued_to": "o37l8g.apps.googleusercontent.com",
    "audience": "o37l8g.apps.googleusercontent.com",
    "user_id": "113504",
    "expires_in": ​814,
    "issued_at": ​1452991611,
    "email": "[email protected]",
    "email_verified": true

}

I tried to use other endpoints, like https://www.googleapis.com/oauth2/v1/tokeninfo?access_token= and https://www.googleapis.com/oauth2/v1/userinfo?access_token=, but none of them worked.

I also tried with the playground but cannot find which endpoint to use, my scope is well defined and I see in the iOS app that all the permissions are requested, but somehow it still doesn't return the user's name... Any ideas?

like image 260
Kali Aney Avatar asked Jan 17 '16 01:01

Kali Aney


1 Answers

You should use the access_token instead of the id_token, so you will be still able to query the tokeninfo endpoint to very your token using:
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=

But now you can also query other endpoints to access to other informations, like the name:
https://www.googleapis.com/plus/v1/people/me?access_token=

Check how you use the Google SignIn iOS SDK and make sure you are getting end sending to your server the access_token instead of the id_token.

example in Swift:

 func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
     let token = user.authentication.accessToken // YES
     let token = user.authentication.idToken // Maybe NO 
 ...
like image 102
Cesar Avatar answered Sep 21 '22 18:09

Cesar