无法为 Google webapp 使用 Google 登录验证器按钮?

Not possible to use Google login authenticator button for Google webapp?

尝试对 Google 网络应用程序使用 Google 联合身份验证登录按钮时,错误消息发现与相关 URI 和 javascript 主机域不匹配。 2019 post (Get gmail address using Google Apps Script, Error: redirect_uri_mismatch) 中的解决方案对我不起作用。

然后我找到了这篇最近的文章:What is the Authorized Javascript Origin for a webapp powered by Google Script?

我的理解是,由于 Google 最近的操作,Google 身份验证器不再可能用于 Google webapp,因为重定向 URI 和 javascript 源主机域“不能是 googleusercontent.com”,这是 Google webapps 的主机域。

所以,我的问题在 post 之前(即 2019 年)重复了,但在新的情况下。我引用的最近 post 的结论对我来说似乎太激进了,我正在寻求确认,或者解释我是如何误解它的。

作为背景:我需要 webapp 在“(我)所有者”帐户下运行以连接到所有者电子表格,但还需要用户的 Gmail 地址(必需)以进行应用程序访问控制(没有其他访问用户 Gmail 的权限帐户;用户并非都在共享 Workspace 域中)。 Google 登录将提供用户的 Gmail 地址。所以,在完全放弃这个解决方案之前,我希望得到额外的说明。

根据官方文档,无法使用 Google Sign-In for Websites, and this post from the Google Apps Script Issue tracker Fail to Add *.googleusercontent.com into Authorized JavaScript origins,因为 Google Apps 脚本使用 googleusercontent.com

为了实现你的目标,正如我在你之前的问题中提到的,你可以使用 UrlFeth 服务调用 Google 表格 API 来连接你的电子表格并设置网络应用程序作为用户而不是你。


来自https://developers.google.com/identity/protocols/oauth2/web-server#uri-validation

Domain Host TLDs (Top Level Domains) must belong to the public suffix list.
Host domains cannot be “googleusercontent.com”.
Redirect URIs cannot contain URL shortener domains (e.g. goo.gl) unless the app owns the domain. Furthermore, if an app that owns a shortener domain chooses to redirect to that domain, that redirect URI must either contain “/google-callback/” in its path or end with “/google-callback”.

相关

,您可以通过使用两个网络应用程序并在两者之间管理 authentication/authorization 来解决此问题:

  • 网络应用#1:

    • 运行 为:我
    • 访问:任何人甚至匿名
  • 网络应用#2:

    • 运行 作为:用户
    • 访问:任何人

您可以从 webapp#2 创建一个 jwt 令牌并在 webapp#1 上验证它。由于它是自定义解决方案,因此安全性可能存在问题。

参考文献: