为什么Firebase服务帐户凭据JSON没有JSON的形式?
我已经有一段时间没有尝试使用Firebase Admin SDK,所以如果这很琐碎,我深表歉意,但我已经花了两天时间了。
我正在使用Firebase创建一个新的Web和移动应用程序,为此,我在Web和移动客户端应用程序之间共享了一个数据模型层。我想使用Firebase Node.js Admin SDK设置数据模型的自动测试。
因此,我在此处遵循说明 https://firebase.google.com/docs/admin/setup-
但是,我从firebase下载的服务帐户凭据,尽管确实将其下载为.json文件,但该文件没有JSON文件的形式。它只是一个长的字母数字字符串,最后是'='。
如预期的那样,导出环境变量($ export google_application_credentials = ...),然后调用useApplicationDefault()
导致意外的令牌错误。
如果我尝试重建我期望 Think 的数据类型,并将文件中的字符串拉到具有键“ privateKey”的正确格式化的JSON中,那么我会得到此错误: firebaseapperror:凭据文件中的内容无效
如果我尝试使用项目的“服务帐户”页面上的firebase提供的代码段,并带有未编辑的未编辑的非json .json。如预期的那样,令牌,但是如果我将编辑的.json文件与正确构建的JSON一起使用,我会遇到PEM错误。
firebaseapperror:无法解析私有密钥:错误:无效的pem格式化消息。
如前所述,.json文件firebase向我提供的不是JSON,仅包含由'='='sign终止的字母数字字符串。
我编辑的版本具有表格
{
"projectId": "myprojectid-id123",
"clientEmail": "[email protected]",
"privateKey": "abcde1234567890="
}
I have not attempted to use the Firebase Admin SDK for some time, so I apologize if this ends up being trivial but I have spent two days on this.
I am creating a new web and mobile app using Firebase, for which I have a data model layer shared between the web and mobile client apps. I want to set up automated testing of the data models using the Firebase Node.js Admin SDK.
So, I followed the instructions here https://firebase.google.com/docs/admin/setup
However, the service account credentials I download from firebase, although it is indeed downloaded as a .json file, the file does not have the form of a JSON file. It is just a long alphanumeric string with an '=' at the end.
As expected, exporting the environment variable ($ export GOOGLE_APPLICATION_CREDENTIALS=...) and then calling useApplicationDefault()
results in an unexpected token error.
If I attempt to reconstruct the data type which I think is expected and pull the string in the file into a properly formatted JSON with the key "privateKey", then I get this error:FirebaseAppError: Invalid contents in the credentials file
If I attempt to use the code snippet provided by Firebase on the Service Account page of my project, with the raw unedited non-JSON .json file, I still get unexpected token, as expected, but if I use the edited .json file with the correctly-formatted JSON, I get a PEM error.
FirebaseAppError: Failed to parse private key: Error: Invalid PEM formatted message.
As stated, the .json file Firebase provides to me is not a JSON and only contains an alphanumeric string terminated by an '=' sign.
My edited version has the form
{
"projectId": "myprojectid-id123",
"clientEmail": "[email protected]",
"privateKey": "abcde1234567890="
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论