Idpiframe_initialization_failed on Google Login with Localhost

I am trying to create a Google login button by following this link . While there is an account selection dialog, but after that I do not see the results in the console. Instead, I get this error while loading the page,

"idpiframe_initialization_failed", details: "Not a valid origin for the client: http://localhos…itelist this origin for your project client ID."
details: "Not a valid origin for the client: http://localhost has not been whitelisted for client ID 386404527657-q4ss06np5g27dllq5ds7aif42udkh7e5.apps.googleusercontent.com. Please go to https://console.developers.google.com/ and whitelist this origin for your project client ID."

Here are the codes

<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>
    <script>
      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);
      };
    </script>
  </body>
</html>

I really need to fix this problem and get the results in my console. I have no idea what to do next to fix this. Need help with this, thanks!

+12
5

, .

: .

Chrome: → → →

+30

, , , API Google .

+3

Google " JavaScript"

0

, Cliff Coulter, .

0

I encountered this error on several sites that offer Google Login. I had to “allow” the use of the cookie account.google.com in the “Show cookies and other site data” section in order for the site to work (after reloading the page). Probably the primary reason was blocking third-party cookies in the browser,

0
source

Source: https://habr.com/ru/post/1686557/


All Articles