Search code examples
google-cloud-platformgoogle-oauthgoogle-api-javascript-client

How to use the GAPI Client Library (Google Sign-In for Web) for existing apps after March 31, 2023 for the example given?


The GAPI Client Library (Google Sign-In for Web) is being deprecated after March 31, 2023, but:

existing client IDs created before July 29th, 2022 may set the plugin_name to enable use of the legacy Google platform library.

See: https://developers.google.com/identity/sign-in/web/reference

Before March 31, 2023, an existing page (given below) will print the googleUser object to console after a successful Google Sign-In:

<html>
  <head>
      <meta
        name="google-signin-client_id"
        content="*****************.apps.googleusercontent.com"
      />
      <meta
        name="google-signin-scope"
        content="https://www.googleapis.com/auth/analytics.readonly"
      />
    <title>Google Login Example</title>
  </head>
  <body>

      <!-- The Sign-in button. This will run `init()` on success. -->
      <p class="g-signin2 mt-4 mb-4 screen-only" data-onsuccess="init"></p>

      <script>
      function init(googleUser) {
        console.log(googleUser);
      }
      </script>

      <!-- Load the JavaScript API client and Sign-in library. -->
      <script src="https://apis.google.com/js/client:platform.js"></script>
  
  </body>
</html>

The documentation suggests that adding plugin_name as part of the gapi.auth2.ClientConfig object will allow an existing integration to work for a while longer.

The sample above does not have a gapi.auth2.ClientConfig specified, but does have meta tags for client_id and scope (which are parameters for gapi.auth2.ClientConfig).

To get this example working after March 31, 2023, do I just add a meta tag in this format?

<meta name="google-signin-CLIENT_CONFIG_PARAMETER_NAME" content="CLIENT_CONFIG_PARAMETER_VALUE" />

Like so?

<meta name="google-signin-plugin_name" content="My App Name Here" />

Solution

  • OK, now we're after March 31, 2023, I can answer this.

    The method described above, adding...

    <meta name="google-signin-plugin_name" content="My App Name Here" />
    

    ..does appear to work just fine.

    Just replace My App Name Here with something more descriptive for your app.