首頁  >  問答  >  主體

Google 一鍵登入上的無限重定向循環

我無法找到任何關於 Google One Tap UX 以及如何在登入重新導向後保留登入狀態的文件。我正在使用 html api,請在此處查看程式碼:

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>

本質上,我將這個登入彈出視窗延遲了 30 秒,該部分工作正常,但不久之後就會發生這種情況:

  1. 登入發生
  2. 發生重定向
  3. 伺服器重新導向回引用頁面
  4. 30 秒後,過程再次開始

我以為 google sdk 會在某個地方設定 cookie 或其他東西,但我想它不會,或者我應該透過自己的方式處理持久登入狀態。我只是想知道這裡的正確方法。

我的問題是:Google 如何知道使用者是否已使用 Google One Tap UX 登入?

P粉463840170P粉463840170203 天前421

全部回覆(1)我來回復

  • P粉115840076

    P粉1158400762024-03-30 00:31:08

    想出了一個解決辦法。 Google 允許您在 div 標籤上放置一個名為 data-skip_prompt_cookie="yourcookie" 如果該 cookie 具有真實值,這將跳過一鍵提示

    我所做的是在 asp.net 中的伺服器回呼中,我為回應新增了一個 cookie。這可確保只有在有人實際登入後才會停用提示。

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

    這可以確保當我的伺服器重定向回原始頁面時,cookie 存在並且一鍵點擊不會再次出現

    回覆
    0
  • 取消回覆