admin管理员组

文章数量:1314320

The Google Sign-in platform can be forced to use the new FedCM APIs by setting use_fedcm to true when initializing the library, according to

Typically, initialization looks like:

  • gapi.client.init({use_fedcm: true}), or
  • gapi.auth2.init({use_fedcm: true}), or
  • gapi.auth2.authorize({use_fedcm: true}).

My webapp uses the library, but does not initialize it with any such calls:

<head>
  <meta name="google-signin-client_id" content="MY-CLIENT-ID">
  <meta name="google-signin-hosted_domain" content="MY-DOMAIN">
  <script src=".js" async defer></script>
  <script>
function onSignIn(googleUser) {
  console.print("id_token=", googleUser.getAuthResponse().id_token);
}
  </script>
</head>

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

How can I set use_fedcm

The Google Sign-in platform can be forced to use the new FedCM APIs by setting use_fedcm to true when initializing the library, according to https://developers.google/identity/sign-in/web/gsi-with-fedcm#conduct_an_impact_assessment

Typically, initialization looks like:

  • gapi.client.init({use_fedcm: true}), or
  • gapi.auth2.init({use_fedcm: true}), or
  • gapi.auth2.authorize({use_fedcm: true}).

My webapp uses the library, but does not initialize it with any such calls:

<head>
  <meta name="google-signin-client_id" content="MY-CLIENT-ID">
  <meta name="google-signin-hosted_domain" content="MY-DOMAIN">
  <script src="https://apis.google/js/platform.js" async defer></script>
  <script>
function onSignIn(googleUser) {
  console.print("id_token=", googleUser.getAuthResponse().id_token);
}
  </script>
</head>

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

How can I set use_fedcm

Share Improve this question asked Jan 31 at 15:38 alebaleb 2,5621 gold badge30 silver badges49 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The gapi.auth2.init(params) method accepts in addition to use_fedcm the client_id and hosted_domain which are passed as google-signin-client_id and google-signin-hosted_domain in the <head> of the page. We can assume that similarly it works to set google-signin-use_fedcm.

  <meta name="google-signin-use_fedcm" content="true">

https://developers.google/identity/sign-in/web/reference#gapiauth2initparams

We know this has an effect because if we init gapi.auth2 like this, it works fine:

  <script src="https://apis.google/js/platform.js?onload=init" async defer></script>
  <script>
function init() {
        console.log("init was here");
        gapi.load('auth2', function() {
                // gapi.auth2 has been loaded successfully.
                gapi.auth2.init({
                        client_id: '{{.ClientId}}',
                        hosted_domain: '{{.Domain}}',
                        scope: 'profile email',
                        use_fedcm: true
                });
                console.log("init was here2");
        });
}
  </script>

.. whereas setting use_fedcm: false fails with an exception: "gapi.auth2.ExternallyVisibleError: gapi.auth2 has been initialized with different options"

本文标签: