如何通过 Google Apps 脚本安全地调用 Google Cloud Function?
? 我有一个谷歌云函数,我可以访问https://MY_REGION-MY_PROJECT.cloudfunctions.net/MY_FUNCTION它,我想允许某些用户通过应用程序脚本调用。
? 为了保护云功能,我已将云功能调用程序设置为仅包含已知电子邮件(例如USER@COMPANY.com,这是有效的 Google 电子邮件)。
? 我能够通过卷曲成功地调用云功能,在登录到gcloud与此电子邮件,通过运行:curl https://MY_REGION-MY_PROJECT.cloudfunctions.net/MY_FUNCTION -H "Authorization: Bearer $(gcloud auth print-identity-token)"。
? 我已在我的 Apps 脚本清单中授予以下 oauthScopes:
"https://www.googleapis.com/auth/script.external_request""https://www.googleapis.com/auth/userinfo.email""https://www.googleapis.com/auth/cloud-platform"?? 但是,当我尝试通过 Google Apps 脚本调用云函数时,在使用电子邮件登录时USER@COMPANY.com,我无法调用它,而是返回了 401。这是我尝试调用云函数的方法:
const token = ScriptApp.getIdentityToken();
const options = {
headers: {'Authorization': 'Bearer ' + token}
}
UrlFetchApp.fetch("https://MY_REGION-MY_PROJECT.cloudfunctions.net/MY_FUNCTION", options);
Run Code Online (Sandbox Code Playgroud)
?? 我还尝试了以下方法:
ScriptApp.getOAuthToken()openid.https://script.google.com并将其设置为授权的 Javascript 来源。oauth google-apps-script oauth-2.0 google-oauth google-cloud-functions
为所有 Firebase 用户设置第一个自定义声明的标准、安全方法是什么?
Firebase 提供了一些很棒的文档和示例来理解和使用自定义声明(例如这个很棒的视频示例),但大多数示例使用现有的自定义声明来授权创建其他自定义声明;截至本文,Firebase 控制台无法设置/编辑/查看自定义声明,也无法通过 CLI 设置自定义声明。
以下是我正在考虑的一些选择:
您是否遇到过这个问题并更优雅地解决了它?