node.js - Cloud Functions Shell 中 initializeApp() 上的 Firebase 无效凭据 302
问题描述
为了加快我的开发/测试速度,我尝试开始使用 Cloud Functions:shell,而不是在每次进行微小更改时部署 --only 功能。
不过,我收到“无效凭据”错误。
这是一个基本的工作index.js 文件:
const express = require("express");
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const app = express();
app.get("/say_hi", (req, res) => console.log("HI!"));
exports.oauth = functions.https.onRequest(app);
以下是我在 CLI 中从 shell 调用函数的方式:
> firebase functions:shell
> oauth.get("say_hi")
输出是“嗨!” 写入控制台,这很好。
问题是当我尝试在以下函数中使用 admin.database() 时:
app.get("/get_ref", (req, res) => admin.database().ref("users"));
这是输出错误:
"code": "app/invalid-credential",
"message": "Credential implementation provided to initializeApp() via the 'credential' property failed to fetch a valid Google OAuth2 access token with the following error: 'Error fetching access token: 302 Found'"
我已经阅读了 '302 found' code ad 'invalid-credentials' 的文档,但这并没有告诉我太多关于解决问题的方法,所以我开始想知道我是否需要一个服务帐户来初始化 Admin SDK,但是没有意义,因为当我运行部署时,功能无缝运行,我可以读取/写入实时数据库/从实时数据库读取/写入。
这里有什么问题?
解决方案
您是否尝试过设置GOOGLE_APPLICATION_CREDENTIALS
环境变量?它可能会解决您的问题:https ://firebase.google.com/docs/functions/local-emulator
在这种情况下,使用 Cloud Functions Shell 时查看此使用服务帐户凭据可能会有所帮助。
推荐阅读
- flutter - 如何将 searchBar 放入 appBar - Flutter?
- performance - 避免在 Python 中的大型数据集上创建密集矩阵
- python - 带有 if 语句的 pd df 中的 Lambda 函数导致语法错误
- javascript - 如何修改这个 axios 对象,以便我可以在各种标题之间进行选择?
- php - 选择标签不显示新选择的选项
- memory - POD 内存利用率和 Node ps 的 RSS 差异
- android - 未解决的参考:当使用 LiveData 将值从一个片段传递到另一个片段时,选择器上的 setOnClickListener
- javascript - 使用 eventRender 在完整日历 api 中附加子元素?
- python - Django 使用 xhtml2pdf 从模板生成 pdf
- javascript - 部分 div 边框被切断