如何在带有NodeJS的Google Cloud Storage中使用google-auth-library? [英] How to use google-auth-library with Google Cloud Storage with NodeJS?

本文介绍了如何在带有NodeJS的Google Cloud Storage中使用google-auth-library?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在NodeJS中使用 Google云存储,但需要通过 google-auth-library 具体来说:我想将其托管在heroku上,所以我想将秘密保存在环境变量中,而不是在文件中(因为我必须提交文件才能部署到heroku).基本上在auth库中建议什么: https://github.com/googleapis/google-auth-library-nodejs#loading-credentials-from-environment-variables

I want to use Google Cloud Storage in NodeJS but authenticate with google-auth-library Specifically: I want to host this on heroku, so I want to keep the secret in an environment variable, not in a file (as I'd have to commit the file to deploy to heroku). Basically what is suggested in the auth library: https://github.com/googleapis/google-auth-library-nodejs#loading-credentials-from-environment-variables

但是我似乎无法将生成的客户端传递给Storage构造函数?

But I can't seem to pass the resulting client to the Storage constructor?

推荐答案

读取代码[ 3 4 5 ],您应该可以将凭据作为构造函数选项传递:

Reading the code [1,2,3,4,5] you should be able to pass in credentials as constructor options:

storageOptions = {
  projectId: 'your-project-id',
  credentials: {
        client_email: 'your-client-email',
        private_key: 'your-private-key'
  }
};
client = new Storage(storageOptions);

这篇关于如何在带有NodeJS的Google Cloud Storage中使用google-auth-library?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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