Google Sign-In: Migration to Federated CM

247 Views Asked by At

I have a website with Google Sign-In. Recently, I received an email from Google, saying that I will be migrated to Federated CM (FedCM) by 4.2024. I do not understand what it is and what it means. The email links to this page for guidance, but I do not see how to implement it in my code. Specifically, my current code looks like this:

    <script type='text/javascript' src='https://apis.google.com/js/platform.js?onload=onLoad' async defer></script>
    <meta name='google-signin-client_id' content='$GLOBALS[google_signin_client_id].apps.googleusercontent.com'>
    <style>
        iframe#ssIFrame_google {display:none}
    </style>
    <script type='text/javascript'>
        function onLoad() {
                if (!gapi.auth2) {
                    gapi.load('auth2', function() {
                        gapi.auth2.init();
                    });
                }
        }
        
        function onSignIn(googleUser) {
                var profile = googleUser.getBasicProfile();
                var redirectUrl = '?followup=$followup&id='+encodeURIComponent(profile.getId())+'&name='+encodeURIComponent(profile.getName())+'&email='+encodeURIComponent(profile.getEmail())+'&image='+encodeURIComponent(profile.getImageUrl());
                window.location = redirectUrl;
        }
    </script>

and the first step in the migration guide says:

  1. Add a boolean flag to enable FedCM when initializing using:
  • HTML, set the data-use_fedcm_for_prompt attribute to true.

  • JavaScript, set use_fedcm_for_prompt to true in the IdConfiguration object.

In my code, I do not see where I need to set the data-use_fedcm_for_prompt flag to true (on which object exactly)? And I do not see any IdConfiguration project.

What do I need to do for a successful migration?

2

There are 2 best solutions below

3
Salahable On

Replace the platform.js script with the FedCM client library

<script src="https://accounts.google.com/gsi/client" async></script>

and for the FedCM prompt, I think this is how it goes, will skip the HTML and use the JavaScript to load FedCM in the gapi.auth2.init() function.

<script type='text/javascript'>
        function onLoad() {
                if (!gapi.auth2) {
                    gapi.load('auth2', function() {
                        gapi.auth2.init();
                            use_fedcm_for_prompt: true  // Enable FedCM
                    });
                }
        }

This is it i think, hope that helps

0
hermz On

Your sample code shows that you are using the deprecated Google Sign-in JavaScript library. You should migrate to the new Sign in with Google library. FedCM is only applicable for the new library.

Thanks, Herman