是否可以在Google Apps脚本网络应用中使用多种身份验证? [英] Is it possible to use multiple authentications in a Google Apps Script web-app?
问题描述
我知道如何编写网络应用程序并以我自己的身份发布.我正在尝试发布一个Web应用程序,以便它可以和访问我的数据.
I know how to write a web-app and publish it as myself. What I am trying to do is publish a web app so that it can access my data and the users data.
例如,Web应用程序将从我拥有的工作表中读取数据,然后将其添加到用户拥有的工作表中.
For example, the web-app would read data from a Sheet that I own, and then add it to a Sheet the user owns.
我意识到一种方法是使具有链接的任何人都可以访问我的工作表,并使Web应用程序在用户的上下文中运行.当用户查看该网络应用程序时,它将在用户的上下文中运行,因此它可以访问他们的工作表和我的拥有链接的任何人都可以查看工作表.该链接将可以访问我的工作表.
I realize one approach is to make my sheet accessible by anyone with the link and have the web-app run in the user's context. When the user views the web-app it will run in the user's context so it can access their Sheet and Since my sheet is viewable by anyone with a link it will be able to access my Sheet.
但是,我试图做到这一点,而不会使具有链接的任何人访问我的工作表.
However, I am trying to do this without making my sheet accessible by anyone with a link.
这可能吗?
推荐答案
解决方法#1:两个Web应用
使用两个Web应用程序并处理这两个Web应用程序之间的身份验证:
Workaround#1: Two web apps
Use two web apps and handle authentication between those two:
-
WebApp#1:用于访问工作表的API
- 以"Me"身份执行
- 访问权限:任何人,甚至是匿名的"
- 处理传入的POST请求:检查必要的授权,验证请求并从工作表返回数据.
WebApp#2:面向用户的应用程序
- 以用户正在访问网络应用"身份执行
- 访问权限:任何人"
- 用户从您的工作表中请求数据>客户端请求Server(
google.script.run
)>服务器POST请求以及使用UrlFetchApp
>的必要授权标头接收并解析工作表数据并将其提供给客户端.
- Execute as "User accessing the web app"
- Access: "Anyone"
- User requests data from your sheet> Client requests Server(
google.script.run
)> Server POSTs request along with necessary authorization headers usingUrlFetchApp
> receives and parses the sheet data and provides it to client.
注释:
- 此设置的安全性仅与网络应用之间使用的授权/身份验证一样强.
-
在您的Web应用程序中
-
实施 Google登录.
Implement Google signin in your webapp.
- 以"Me"身份执行
- 访问权限:任何人,甚至是匿名的"
- 访问Web应用程序的用户必须登录
- 登录并授权访问其工作表后,您可以使用工作表api写入其工作表
参考文献:
- Google sign-in
- Sample snippet: Sheets api access from browser
- Related question
这篇关于是否可以在Google Apps脚本网络应用中使用多种身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!