为什么 Django 中的 Google-Auth(Google Identity) 弹出窗口空白?

发布于 2025-01-12 05:11:23 字数 1552 浏览 6 评论 0原文

我的 Google 身份验证卡在弹出身份验证流程中。一键式身份验证工作正常,但按钮

不行。我点击它,弹出窗口打开,但它仍然空白,没有任何进展。

<script>
   function handleCredentialResponse(response) {
     console.log("Encoded JWT ID token: " + response.credential);
     ...
    }
   window.onload = function () {
     google.accounts.id.initialize({
       client_id: "531144-------",
       callback: handleCredentialResponse
     });
     google.accounts.id.renderButton(
       document.getElementById("g_id_signin"),
       { theme: "outline", size: "large" }  // customization attributes
     );
     google.accounts.id.prompt(); // also display the One Tap dialog
   }
</script>
<div id="g_id_signin"></div>

我拥有所有域,在授权重定向 URI 和重定向中添加了 localhost。但我仍然无法让弹出窗口填充并完成身份验证流程。 任何帮助表示赞赏。

此时我在 FIREFOX 中遇到的错误:

未捕获类型错误:window.opener 为 null li https://ssl.gstatic.com/_/gsi/_/js/k=gsi.gsi.en.i....O/am=wg/d=1/rs=AF0... w/m=credential_page_library:291 mi https://ssl.gstatic.com/_/gsi/_/js/k=gsi.gsi.en.i.....O/am=wg/d=1/rs=AF0.. .w/m=credential_page_library:29

在 CHROME 中:

未捕获的类型错误:无法读取 null 的属性(正在读取 '发布消息') 在李 (m=credential_page_library:291:151)

My Google Auth is Stuck in the popup auth flow. The one-tap authentication works just fine but not the button<div id="g_id_signin"></div>. I click on it, the popup opens but it remains there blank with no progress.

<script>
   function handleCredentialResponse(response) {
     console.log("Encoded JWT ID token: " + response.credential);
     ...
    }
   window.onload = function () {
     google.accounts.id.initialize({
       client_id: "531144-------",
       callback: handleCredentialResponse
     });
     google.accounts.id.renderButton(
       document.getElementById("g_id_signin"),
       { theme: "outline", size: "large" }  // customization attributes
     );
     google.accounts.id.prompt(); // also display the One Tap dialog
   }
</script>
<div id="g_id_signin"></div>

I have all the domains, localhost added in Authorized redirect URIs and Redirects. But I still can't get the popup to populate and complete the authentication flow.
Any help is appreciated.

At this point the error I am getting in FIREFOX:

Uncaught TypeError: window.opener is null
li https://ssl.gstatic.com/_/gsi/_/js/k=gsi.gsi.en.i....O/am=wg/d=1/rs=AF0...w/m=credential_page_library:291
mi https://ssl.gstatic.com/_/gsi/_/js/k=gsi.gsi.en.i.....O/am=wg/d=1/rs=AF0...w/m=credential_page_library:29

And in CHROME:

Uncaught TypeError: Cannot read properties of null (reading
'postMessage')
at li (m=credential_page_library:291:151)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦年海沫深 2025-01-19 05:11:23

您必须在settings.py中将SECURE_CROSS_ORIGIN_OPENER_POLICY设置为“same-origin-allow-popups”

参考:https://github.com/google/google -api-javascript-client/issues/796#issuecomment-1118136612

You have to set SECURE_CROSS_ORIGIN_OPENER_POLICY to "same-origin-allow-popups" in settings.py.

Reference: https://github.com/google/google-api-javascript-client/issues/796#issuecomment-1118136612

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文