首页 > 解决方案 > 传入的 JSON 对象不包含 client_email 字段

问题描述

我正在尝试创建一个 Firebase 云功能。所以我想在本地运行我的 firebase 云功能。但是如何设置身份验证不起作用。

我已经安装了 firebase 工具:https ://firebase.google.com/docs/functions/local-emulator 我已经运行了命令firebase login,所以现在我已经登录了。然后我用本教程创建了我的 json 密钥:https ://cloud.google.com/docs/authentication/getting-started 现在如果我输入echo $GOOGLE_APPLICATION_CREDENTIALS结果是/home/$USER/.google/****.json包含

"project_id","private_key_id","private_key","client_email", "client_id",  "auth_uri", "token_uri", "auth_provider_x509_cert_url", "client_x509_cert_url"

此外,我尝试安装完整的 google cloud sdk 并运行:gcloud auth application-default login但没有成功。

Npm 包版本:

"firebase-functions":"3.0.2"
"firebase-admin": "8.2.0"

我想我已经提供了足够的信息,但如果您愿意,请随时问我。

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const express = require("express");
const app = express();
app.get("/", async (req, res) => {
admin.firestore().collection('something').get().then((collection) =>
    return res.send({"count": collection.docs.length, "status": 200});
});
exports.exports = functions.https.onRequest(app);

代码并不重要,最重要的是即使我已经完成了所有这些步骤,当我在本地模拟我的firebasefirebase serve并触发一个函数时,我有这个错误:错误:传入的JSON对象不包含client_email场地

我可以确保您的 json 文件包含 client_email 字段。

你能帮我通过谷歌进行身份验证吗?

谢谢你的帮助。

标签: javascriptfirebasegoogle-cloud-functionsfirebase-admingoogle-auth-library

解决方案


我有一个类似的问题。这可能7.0.2firebase-tools. 我回滚到版本7.0.0,它现在可以工作了。

所以临时解决办法是:

npm i firebase-tools@7.0.0 -g  

推荐阅读