Migrating Away From Userinfo

· March 5, 2014

As part of the move to full OpenID connect support recently, the “userinfo” scopes and endpoint were deprecated and scheduled for shutdown in September 2014. If you are using the userinfo API endpoint to retrieve email address or profile information for a Google user, now is the time to change! Luckily, it’s just a few minutes of work to move from the userinfo API to the people.get API for most people, and wont affect users at all.

What should you do?

  1. Check whether you’re using userinfo
  2. Update scopes
  3. Replace userinfo API call with a call to plus.people.get

Are you using the endpoint?

Look for the section in your code where you retrieve the user’s profile or email address. If you make the API call directly, you may see a URL like “https://www.googleapis.com/oauth2/v1/userinfo”. The “v1” might also be “v2” as there are a couple of different versions of the api, but if it has /oauth2 then you’re using the userinfo endpoint. If you’re using a client library, look for using the (somewhat confusingly named) OAuth2 service or API. For example:

PHP: new Google_Service_Oauth2($client);
Python: service = build('oauth2', 'v2', http=http)
Java: oauth2 = new Oauth2.Builder(httpTransport, JSON_FACTORY, credential).build();

All of these are indicative of retrieving the user data from the userinfo API, and will need to be changed before September 2014.

What scopes should you use?

https://www.googleapis.com/auth/userinfo.profile and https://www.googleapis.com/auth/userinfo.email can be seamlessly replaced with the shorter strings profile and email. These are aliases, so they wont require the user to reconsent if they’ve already give access. If you’re thinking about a larger change, check out my earlier post about choosing a sign in scope.

What API should you call?

All profile information for Google users is now served from the people.get API. This works for users whether or not they have a Google+ profile. It returns data in a slightly different format to the userinfo API, so you may have to change your code a little, but all the same data is available. A call to retrieve the users name, picture and email address would look like this in PHP (and should be analogous with any of the client libraries).

You can actually try the call direct from the “Try It” section at the bottom of the API page to see what the returned data looks like.

What if you want to make the smallest code change possible?

If you aren’t using a client library, and don’t want to change the parsing you’re using, you can call the special getOpenIdConnect method, which returns data in the same format as userinfo. The only difference needed then is looking for the “sub” field rather than “id” (this was a spec change made during the development of OpenID Connect). Take a look at the differences between the calls to the API below

Userinfo API response

https://www.googleapis.com/oauth2/v1/userinfo?access_token=ya29.1.AA...{ "id": "104824858261236811362", "email": "ian@example.com", "verified_email": true, "name": "Ian Barber", "given_name": "Ian", "family_name": "Barber", "link": "https://plus.google.com/+IanBarber", "picture": "https://lh6.googleusercontent.com/-DXmOngLN6Gc/AAAAAAAAAAI/AAAAAAAAGc4/Roeci0EovY8/photo.jpg", "locale": "en-GB"}

openIdConnect API response:

https://www.googleapis.com/plus/v1/people/me/openIdConnect?access_token=ya29.1.AA>...{ "kind": "plus#personOpenIdConnect", "sub": "104824858261236811362", "name": "Ian Barber", "given_name": "Ian", "family_name": "Barber", "profile": "https://plus.google.com/+IanBarber", "picture": "https:https://lh6.googleusercontent.com/-DXmOngLN6Gc/AAAAAAAAAAI/AAAAAAAAGc4/Roeci0EovY8/photo.jpg?sz=50", "email": "ian@example.com", "email_verified": "true", "locale": "en-GB"}

In both cases, you do get a fair bit less than using the people.get API, so I would strongly recommend using people.get where possible!

There are a lot more tips on migrating to the newer sign-in options on the auth migration page, and of course if you have any questions drop into the StackOverflow tags for google-plus and google-oauth.