[auth] Replace people.get with userinfo enpoint

G+ public apis have been deprecated and need to be migrated
to the existing oauth2 userinfo endpoint as part of migration.
This cl also removes some unused deprecated scopes like
userinfo.email and userinfo.profile.

AUTH-133 #done

TESTED = Manual login, CI/CQ

Change-Id: I765c801536232a1a54f8a82d5e91fb1b9307d230
diff --git a/auth_providers/google/constants.h b/auth_providers/google/constants.h
index f5f74e1..e27f96c 100644
--- a/auth_providers/google/constants.h
+++ b/auth_providers/google/constants.h
@@ -16,8 +16,8 @@
     "https://www.googleapis.com/oauth2/v4/token";
 constexpr char kGoogleRevokeTokenEndpoint[] =
     "https://accounts.google.com/o/oauth2/revoke";
-constexpr char kGooglePeopleGetEndpoint[] =
-    "https://www.googleapis.com/plus/v1/people/me";
+constexpr char kGoogleUserInfoEndpoint[] =
+    "https://www.googleapis.com/oauth2/v3/userinfo";
 constexpr char kFirebaseAuthEndpoint[] =
     "https://www.googleapis.com/identitytoolkit/v3/relyingparty/"
     "verifyAssertion";
@@ -25,16 +25,15 @@
 constexpr char kWebViewUrl[] = "web_view";
 
 constexpr auto kScopes = {
+    // Used by google_auth_provider for retrieving unique user profile id.
     "openid",
-    "email",
-    "https://www.googleapis.com/auth/assistant",
+    // Used by google_auth_provider for retrieving user profile attributes,
+    // specifically display name, profile url and profile image.
+    "profile", "https://www.googleapis.com/auth/assistant",
     "https://www.googleapis.com/auth/gmail.modify",
-    "https://www.googleapis.com/auth/userinfo.email",
-    "https://www.googleapis.com/auth/userinfo.profile",
     "https://www.googleapis.com/auth/youtube.readonly",
     "https://www.googleapis.com/auth/contacts",
     "https://www.googleapis.com/auth/drive",
-    "https://www.googleapis.com/auth/plus.login",
     "https://www.googleapis.com/auth/calendar.readonly",
     "https://www.googleapis.com/auth/devstorage.read_write"};
 
diff --git a/auth_providers/google/google_auth_provider_impl.cc b/auth_providers/google/google_auth_provider_impl.cc
index 68d7942..8d0c954 100644
--- a/auth_providers/google/google_auth_provider_impl.cc
+++ b/auth_providers/google/google_auth_provider_impl.cc
@@ -432,7 +432,7 @@
   FXL_DCHECK(credential.get().size() > 0);
   FXL_DCHECK(access_token.get().size() > 0);
 
-  auto request = OAuthRequestBuilder(kGooglePeopleGetEndpoint, "GET")
+  auto request = OAuthRequestBuilder(kGoogleUserInfoEndpoint, "GET")
                      .SetAuthorizationHeader(access_token.get());
 
   auto request_factory = [request = std::move(request)] {
@@ -446,31 +446,39 @@
 
     auto oauth_response = ParseOAuthResponse(std::move(response));
     if (oauth_response.status != AuthProviderStatus::OK) {
-      LogOauthResponse("GetUserProfile", oauth_response);
+      LogOauthResponse("UserInfo", oauth_response);
       get_persistent_credential_callback_(oauth_response.status, credential,
                                           std::move(user_profile_info));
       return;
     }
 
-    if (oauth_response.json_response.HasMember("id")) {
-      user_profile_info->id = oauth_response.json_response["id"].GetString();
+    if (oauth_response.json_response.HasMember("sub")) {
+      user_profile_info->id = oauth_response.json_response["sub"].GetString();
+    } else {
+      LogOauthResponse("UserInfo", oauth_response);
+      FX_LOG(INFO, NULL, "Missing unique identifier in UserInfo response");
+      get_persistent_credential_callback_(
+          AuthProviderStatus::OAUTH_SERVER_ERROR, nullptr,
+          std::move(user_profile_info));
+      return;
     }
 
-    if (oauth_response.json_response.HasMember("displayName")) {
+    if (oauth_response.json_response.HasMember("name")) {
       user_profile_info->display_name =
-          oauth_response.json_response["displayName"].GetString();
+          oauth_response.json_response["name"].GetString();
     }
 
-    if (oauth_response.json_response.HasMember("url")) {
-      user_profile_info->url = oauth_response.json_response["url"].GetString();
+    if (oauth_response.json_response.HasMember("profile")) {
+      user_profile_info->url =
+          oauth_response.json_response["profile"].GetString();
     }
 
-    if (oauth_response.json_response.HasMember("image")) {
+    if (oauth_response.json_response.HasMember("picture")) {
       user_profile_info->image_url =
-          oauth_response.json_response["image"]["url"].GetString();
+          oauth_response.json_response["picture"].GetString();
     }
 
-    FX_LOG(INFO, NULL, "Received valid UserProfile");
+    FX_LOG(INFO, NULL, "Received valid UserInfo response");
     get_persistent_credential_callback_(oauth_response.status, credential,
                                         std::move(user_profile_info));
   });