Migrating Google Sign-In auth2 (browser popup) away from Google+ API

Viewed 591

In our app, we have a simple Google-Sign-In flow where a popup opens, users log in and grant us offline permission for accessing Google Analytics.

We just got emailed that we're using a Google+ API (plus.people.getOpenIdConnect method) that is about to get deprecated, but we don't use it in our code.

I can't seem to figure out where we are using Google+ API so I could replace it.

Here is our simple code:

  prepareGoogleClient() {
    $.ajax({
      url: "//apis.google.com/js/client:platform.js",
      dataType: "script"
    }).done(() => {
      gapi.load("auth2", () => {
        let auth = gapi.auth2.init({
          client_id: ENV.googleClientId,
          scope:
            "https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/webmasters.readonly"
        });

        this.auth = auth;
      });

      if (gapi.auth2 && !this.auth) {
        this.auth = gapi.auth2.getAuthInstance();
      }
    });
  }

Later on we call this.auth.grantOfflineAccess(params), which returns the token that we save for later.

If I disable Google+ API in our Google Platform dashboard, the Sign-In stops working and the popup responds with a sign-in error. I was also able to confirm that Google+ API (from its metrics panel) is indeed used in the process of our users signing in the popup and granting scope permissions.

How do I need to rewrite this so it won't use the deprecated plus.people.getOpenIdConnect method?

2 Answers

The issue was in Rails back-end code which handles OAuth2. The outdated omniauth-google-oauth2 gem was using the deprecated Google+ endpoint.

I think everyone using Google+ API's in their app, have got that mail. Don't know if this helps but got this is from google API's site.

The Google+ Sign-in feature has been fully depreciated and will also be shut down on March 7, 2019. Developers should migrate to the more comprehensive Google Sign-in authentication system.

https://developers.google.com/+/web/api/javascript

https://developers.google.com/+/integrations-shutdown

Other References:

  1. List of API's to be removed https://developers.google.com/+/api-shutdown
  2. New Sign(identity) https://developers.google.com/identity/
  3. Identity for web app https://developers.google.com/identity/sign-in/web/

Add Google Sign-In to Your Web App

function onSignIn(googleUser) {
  // Useful data for your client-side scripts:
  var profile=googleUser.getBasicProfile();
  console.log("ID: " + profile.getId()); // Don't send this directly to your server!
  console.log('Full Name: ' + profile.getName());
  console.log('Given Name: ' + profile.getGivenName());
  console.log('Family Name: ' + profile.getFamilyName());
  console.log("Image URL: " + profile.getImageUrl());
  console.log("Email: "+profile.getEmail());
  // The ID token you need to pass to your backend:
  var id_token=googleUser.getAuthResponse().id_token;
  console.log("ID Token: "+id_token);
}
<html lang="en">

<head>
  <meta name="google-signin-scope" content="profile email">
  <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
  <script src="https://apis.google.com/js/platform.js" async defer></script>
</head>

<body>
  <div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>

</body>

</html>

Related