firebase-authentication - google.auth.GoogleAuth() 需要什么 keyFile 密钥?
问题描述
目标
将 googleapis 与 firebase 功能一起使用。获取 JWT 令牌,以便 firebase 函数可以使用具有域范围委派的服务帐户来授权 G Suite API,例如目录和驱动器。
问题
path.join() 中发生了什么;
什么是 __dirname
什么 'jwt.keys.json'
?
从这个例子: https ://github.com/googleapis/google-api-nodejs-client/blob/master/samples/jwt.js
// Create a new JWT client using the key file downloaded from the Google Developer Console
const auth = new google.auth.GoogleAuth({
keyFile: path.join(__dirname, 'jwt.keys.json'), // <---- WHAT GOES IN path.join()
scopes: 'https://www.googleapis.com/auth/drive.readonly',
});
错误
当我跑
const auth = new google.auth.GoogleAuth({
keyFile: path.join(__dirname, "TEST"), // <-- __dirname == /srv/ at runtime
scopes: 'https://www.googleapis.com/auth/drive.readonly',
});
从 GCP 日志中,我收到此错误:
Error: ENOENT: no such file or directory, open '/srv/TEST'
显然TEST
是无效的,但是'/srv/
?
keyFile
文件路径是什么?凭证?
另一个例子
https://github.com/googleapis/google-api-nodejs-client#service-to-service-authentication
解决方案
我在这里找到了文档:
https://googleapis.dev/nodejs/google-auth-library/5.10.1/classes/JWT.html
如果您不想包含文件,您可以在请求授权时使用key
、keyId
和email
提交凭据。
推荐阅读
- pine-script - 在给定特定时间范围(例如 1 小时)的情况下,如何获得最高收盘价和最低收盘价?
- reactjs - React Native - 使用键从数组中删除项目
- powershell - 已弃用的 wmic 的 cmd / batch 替代品是什么?
- javascript - 从乱码元素中隐藏 1 个元素
- lilypond - Lilypond - 不能使用变量作为 \addlyrics 的一部分
- java - 将 org.apache.parquet.example.data.simple.SimpleGroup 转换为 org.apache.avro.generic.GenericData.Record
- javascript - 按数据激活 5 个按钮中的一个按钮
- azure-data-factory - 将 csv 中 2 列或更多列的值连接到 Azure 数据工厂中的单列
- arcore - 如何在前置摄像头中调整 ARCore 光线估计
- java - 如何使用包含数据库的 Rest Api 设计图书馆应用程序