How to migrate from deprecated Google+ Sign-in API to the new Google Identity platform in a MVC project?

There is an open issue on this on the aspnet\docs Github page.

This seems to be a breaking change, as indicated by the following issues on Github:

  • aspnet\AspNetCore: Google+ shutdown will break OAuth provider
  • aspnet\AspNetKatana: Google+ shutdown impacts

Apparently the Google OAuth provider performs a call to https://www.googleapis.com/plus/v1/people/me, which is used to get profile information. As stated by ThoughtHopper, "[t]he current code works until it tries to retrieve the userinfo."

A temporary workaround was posted by Tratcher, which is claimed to work for ASP.NET 2.0 and later:

.AddGoogle(o =>
        {
            o.ClientId = Configuration["google:clientid"];
            o.ClientSecret = Configuration["google:clientsecret"];
            o.UserInformationEndpoint = "https://openidconnect.googleapis.com/v1/userinfo";
            o.ClaimActions.Clear();
            o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub");
            o.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
            o.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_Name");
            o.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_Name");
            o.ClaimActions.MapJsonKey("urn:google:profile", "profile");
            o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
            o.ClaimActions.MapJsonKey("urn:google:image", "picture");
        })

This changes the endpoint from which information is retrieved (no longer relying on Google+) and changes the way user info is mapped since this has changed.

From the amount of attention these issues are receiving I expect an update to be pushed out by Microsoft in the near future. Until then, this fix should work with the Google+ API disabled.