GAS以用户身份运行时的用户访问请求
在作为绑定到公共(免费)Gmail 帐户中的电子表格的 Web 应用程序发布的 GAS 中,我将许多不相关用户的信息编译到该电子表格中,任何 Gmail 用户帐户都可以访问该 Web 应用程序。
但是,当脚本以用户身份运行时,用户可以访问应用程序(在用户向应用程序授予权限后),但它会在脚本访问电子表格的地方停止。用户被告知请求访问权限。我必须将电子表格“共享”给用户,以便应用程序在以该用户身份运行时运行,但这是有问题的——潜在用户太多。
如果在我的帐户下运行脚本的另一个版本,则用户可以访问 web 应用程序,但脚本无法访问用户的 Gmail 地址。这是个大问题,因为网络应用程序必须拥有用户的 Gmail 地址才能进行安全/应用程序访问控制。
(该网络应用程序正在开发中,尚未寻求 Google“批准”。)
我如何拥有一个网络应用程序 (a) 可以修改中央电子表格中的内容,(b) 任何 Gmail 用户都可以访问,(c)脚本可以访问 Session.getActiveUser().getEmail(),并且 (d) 用户不需要拥有该中央电子表格的编辑权限?该脚本所需的唯一用户帐户信息是用户 Gmail 地址——同样是为了应用程序访问控制和安全。 (由于 Google 向我提供了一个链接,可以让任何人完全访问电子表格(如果他们也有其 URL),那么当在任何 Gmail 帐户下运行时,我是否不能授予绑定脚本对电子表格的访问权限,其中电子表格内容的完整性通过应用程序的功能和内部访问控制进行管理?)
如果除了在用户的 Gmail 帐户下运行网络应用程序并授予该用户对电子表格的编辑权限之外没有其他解决方案,这是否会造成重大风险(我无意/公开披露电子表格的 URL)除了网络应用程序执行的插入/编辑功能之外,用户还可以访问和更改电子表格吗?如果风险较低,我是否可以在网络应用程序中使用一个功能,当 Gmail 地址预先注册在网络应用程序的用户列表中时,自动向 Gmail 帐户授予电子表格编辑权限?
谢谢你!
In a GAS published as webapp bound to a spreadsheet in a public (free) Gmail account, I'm compiling information from many unrelated users into that spreadsheet, where any Gmail user account can access the webapp.
But when script is run as the user, the user can access the app (after user grants permissions to the app), but it stops at point where script accesses the spreadsheet. The user is told to request access. I have to "share" the spreadsheet to the user for the app to function when run as that user, but that is problematic--too many potential users.
If another version of the script is run instead under my account, then user has access to the webapp, but the script cannot access the user's Gmail address. Big problem because the webapp must have the user's Gmail address for security/application access controls.
(The webapp is in development and Google "approval" has not yet been sought.)
How do I have a webapp (a) that modifies content in a central spreadsheet, (b) that any Gmail user can access, (c) where the script has access to Session.getActiveUser().getEmail(), and (d) the user does not need to have edit permissions for that central spreadsheet? The only user-account information that the script needs is the user Gmail address--again for application access control and security. (Since Google provides me a link that gives anyone full access to the spreadsheet (if they also have its URL), can't I give the bound script access to the spreadsheet when run under any Gmail account, where the integrity of the spreadsheet content is managed through the app's functions and internal access controls?)
If there is no solution except to run the webapp under the user's Gmail account and give that user edit rights to the spreadsheet, would that create significant risk (where I don't intentionally/overtly disclose the spreadsheet's URL) that a user could access and alter the spreadsheet beyond the insert/edit functions performed by the webapp? If that risk is low, is there a function I could use in the webapp to automatically grant spreadsheet edit rights to a Gmail account when its Gmail address is pre-registered in the user list for the webapp?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我从 c) 开始:除了容器/脚本所有者之外,没有办法让
Session.getActiveUser().getEmail()
适用于免费 Google 帐户(即 gmail.com 帐户) 。关于 a) b) 和 d),您可以使用 Google Sheets API 通过 UrlFetch 服务和服务帐户(而不是电子表格服务或高级表格服务)进行调用。
关于允许任何人编辑中央电子表格,一旦他们通过使用 Google Sheets 应用程序或网络应用程序打开它,他们将能够在 Google Drive > 中找到该电子表格。与我在其他地方共享...恕我直言,就出现问题的可能性而言,风险很大,但就影响而言,取决于几个因素,即,某些更改可能会通过使用版本历史记录来恢复,但电子表格可能会变得已损坏。如果您没有大量使用过 Google Sheets 版本历史记录,那么最好在依赖它作为备份/灾难恢复主要工具之前深入熟悉它。
来自 https://developers.google.com/apps-script/reference /base/session#getactiveuser
相关
Let me start with c): there is no way to make that
Session.getActiveUser().getEmail()
works for free Google accounts (i.e. gmail.com accounts) other than for the container / script owner.Regarding a) b) and d) you might use the Google Sheets API making the calls to it by using UrlFetch Service and a service account instead of the Spreadsheet Service or the Advanced Sheets Service.
Regarding allowing anyone to edit a central spreadsheet, once they open it either by using the Google Sheets apps or by means a web app, they will be able to find the spreadsheet in Google Drive > Shared with me among other places... IMHO the risk in terms of how likely is to have issues is big but in terms of the the impact depends on several factors, i.e. some changes might be reverted by using the version history but spreadsheet might become corrupted. If you have not used Google Sheets version history intensively the best is to get deeply familiar with it before relying on it as a backup / disaster recovery main tool .
From https://developers.google.com/apps-script/reference/base/session#getactiveuser
Related