共享 google 驱动器 API 凭据以供脚本使用的最佳做法?

Best practice to share google drive API credentials for being used by a script?

简而言之: 我可以在我们的源代码中共享 oauth2-credentials 以及对 google 驱动器的完全写入权限吗来自专用的单一用途 google-帐户?

所以,我写了一个 python 脚本,它将一些数据保存到预先存在的 google-sheets 文件中,或者创建一个新的 google-sheets 文件到给定 google 驱动器文件夹(这两个都是 public 可编辑的,以便在团队之间共享)。

为此,我遵循了 google 和其他来源概述的步骤和教程,此后我获得了我的脚本需要的 oauth2 凭证,以便使用 google 驱动器和 google 张 API。

这些凭据来自我为此脚本创建的单一用途 google 帐户。

现在我想与其他团队成员分享这个脚本,但不确定如何处理凭据;或者:

A.)

I would incorporate the suggested google workflow which would let the user of the script authenticate him/herself, i.e. the user starts the script, then is directed to the google-authentication weblogin, authenticates the script, and then the script would save and use those credentials of the user for writing data into a public google-sheets file (not necessarily a private one owned by the user).

这有以下缺点:

B.)

hardcode the credentials of our single-purpose account into the script; which has the only downside that when the script's source code would be shared, that anyone could obtain those credentials. But these credentials would only enable an attacker to write/read data into the account's google drive, but not take control over the whole account itself due to the limitations of the scope of the oauth2 credentials (I've used the "https://www.googleapis.com/auth/drive" scope). Additionally, as said before, we would only use the script to read/write data into public sheets-files which are owned by real google-accounts, so never would we use the drive of the single-purpose account and thus no attacker could destroy our data.

因此,我宁愿选择选项 B,但我无法缓解硬编码 public 可读凭证带来的焦虑...

你有什么建议?

我们决定选择选项 A:用户需要自己创建 client_secret.json 和 credentials.json 文件。不幸的是,它不是最直接的,但却是最安全的。在 public 存储库中共享凭据是一个很大的禁忌,无论细节如何。

同样为了完整起见:另一种选择是将我们的应用程序 运行 放在我们可以保存 client_secret 的服务器上,这样用户将只看到一个浏览器-弹出 he/she 将授权我们的服务。

但我们也不遵循该选项,因为脚本应仅包含核心逻辑,并且它将作为其他人开发的基础。

这就是我们做出此决定的动机。