有什么方法可以利用Cloud Function auth env var与Google云端硬盘进行交互? [英] Is there any way to utilize Cloud Function auth env vars to interact with Google Drive?

查看:61
本文介绍了有什么方法可以利用Cloud Function auth env var与Google云端硬盘进行交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在部署与Google云端硬盘互动的Cloud Function.据我所知,无法使用隐式的Cloud Function凭据或相关环境变量通过Drive进行授权,因此我不得不求助于在Cloud Function捆绑包中包含certificate.json服务帐户密钥文件或通过在部署Cloud Function期间使用相同的密钥文件来设置环境变量.

I'm deploying a Cloud Function which interacts with Google Drive. As far as I can tell, there's no way to use the implicit Cloud Function credentials or related environment variables to authorize with Drive, so I've had to resort to either including the credentials.json service account key file in the Cloud Function bundle or by setting an environment variable using that same key file during deployment of the Cloud Function.

在我看来,您将能够使用Cloud Function的隐式服务帐户和凭据来实现此目标.

It'd seem to me that you would be able to use the Cloud Function's implicit service account and credentials in order to achieve this.

推荐答案

您可以指定

You can specify a identity service account on Cloud Function. By the way, instead to use the default compute service account, you can use this one that you want.

然后,您可以与服务帐户电子邮件共享文档或共享驱动器.顺便说一下,该功能的服务帐户将有权访问该驱动器元素.

Then you can share a document, or a shared drive with the service account email. By the way, the service account of the function will have access to this drive element.

但是,这还不够.当您执行对Google Drive API的请求时,必须提供身份验证请求标头中的令牌.您可以此处如何请求云功能元数据服务器获取此令牌,然后将其重新用于您的Google Drive API调用.

However, it's not enough. When you will perform the request to the Google Drive API, you have to provide an authentication token in the header of the request. You can find here how to request the Cloud Function metadata server to get this token and then reuse it to your Google Drive API call.

这篇关于有什么方法可以利用Cloud Function auth env var与Google云端硬盘进行交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆