google-apps-script - 如何让用户登录 Google 以访问已部署的 GAS Web 应用程序?

标签 google-apps-script google-signin

我有一个 Google App 脚本 Web 应用程序。我想强制使用 Google 帐户凭据输入。我希望管理员用户通过将帐户请求通过电子邮件发送给管理员用户来“批准”每个新请求,然后仅在管理员用户批准该请求后才允许用户访问 Web 应用程序。我还想根据 Google 凭据引用 session 用户。

我去了this guide并关注CONFIGURE PROJECT窗口中,我无法输入 Web 应用程序的 URL,因为 Invalid Origin: URIs must not contain a path or end with "/".

This是我的网络应用程序的 URL。

此网络应用程序最多可供 5 人使用。

function doGet(){
   //Basic for now: 
   return HtmlService.createHtmlOutputFromFile('mainhtml');
}

如何向用户展示Sign in with Google按钮,然后使用 GmailApp.sendEmail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3051545d595e70555d51595c1e535f5d" rel="noreferrer noopener nofollow">[email protected]</a>', 'Request to join', ) 将该请求发送给管理员

然后,在管理员用户接受请求后,允许用户访问该站点。

最佳答案

本指南用于将 Google Auth 集成到“非 Google”网站。要强制用户进行身份验证(Google 方式),只需使用“谁有权访问该应用程序:任何人”部署您的 GAS Web 应用程序即可。请注意不要选择“任何人,甚至匿名”,这会允许未连接到 Google 的用户访问...

然后为了满足“管理员检查的需要”,我认为没有其他方法可以自己编码:

function doGet(){
   //Control user
   var contentToDisplay;
   if(userIsOk()) { contentToDisplay = HtmlService.createHtmlOutputFromFile('mainhtml');
   } else { 
      sendRequestToAdmin();
      contentToDisplay = HtmlService.createHtmlOutputFromFile('forbiddenhtml'); }
   return contentToDisplay;
}

然后你就可以在“sendRequestToAdmin()”和“userIsOk()”中想象你想要什么。例如,您可以在电子表格中搜索用户电子邮件,其中列出了所有允许的用户。

关于google-apps-script - 如何让用户登录 Google 以访问已部署的 GAS Web 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54342056/

相关文章:

javascript - 无法读取代码中的属性

firebase - 在 firebase 登录中使用 Google Provider 时,应用程序未经过验证

ios - 使用 Google 登录时链接器命令失败,退出代码为 1

javascript - 新的 Google 登录服务按钮自定义

android - Google 登录在 android 5.0(Lollipop) 或以上 Marshmallow 中失败,但在 kitkat handleSignInResult :false 中失败

javascript - 无法访问catch javascript中的变量

xml - 从 Google 电子表格导出到 XML

javascript - 在网络上启用 Google 帐户选择器

javascript - 尝试通过 Google 应用脚本将表单条目(从侧边栏)传递到 Google 表格中的特定列/单元格

forms - 在提交事件中使用 Google App 脚本获取 Google 表单中特定问题/项目的值