Infinite redirect loop on Google one-click login
P粉463840170
P粉463840170 2024-03-29 17:33:57
0
1
417

I can't find any documentation on Google One Tap UX and how to retain logged in status after login redirect. I am using html api, please see the code here:

setTimeout(function () {
    let target = document.getElementById('google-signin');
    target.innerHTML = '<div id="g_id_onload" data-client_id="x" data-context="signin" data-login_uri="https://x/account/google/callback" data-auto_select="true" data-itp_support="true"></div>';
    var s = document.createElement("script");
        s.src = 'https://accounts.google.com/gsi/client';
        
        document.head.appendChild(s);
        
        console.log('appended script', s);
    }, 30000);
</script>

Essentially, I delay this login popup for 30 seconds and that part works fine, but shortly after this happens:

  1. Login occurred
  2. Redirect occurred
  3. Server redirects back to the referring page
  4. After 30 seconds, the process starts again

I would have thought that the google sdk would set a cookie or something somewhere, but I guess it doesn't, or I should handle persistent login status my own way. I just want to know the correct approach here.

My question is: How does Google know if a user is logged in using Google One Tap UX?

P粉463840170
P粉463840170

reply all(1)
P粉115840076

Came up with a solution. Google allows you to place a div tag called data-skip_prompt_cookie="yourcookie" This will skip the one-click prompt if the cookie has a true value.

What I did is in the server callback in asp.net I added a cookie to the response. This ensures that the prompt is only disabled after someone is actually logged in.

Response.Cookies.Append(
            "yourcookie", "true");

This ensures that when my server redirects back to the original page, the cookie is present and the one click doesn't happen again

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!