通过“credential”属性提供给initializeApp()的凭证实现无法获取有效的Google OAuth2

问题描述 投票:0回答:4

我有一个使用 firebase-admin sdk 的 NodeJS Firebase 功能。自去年以来一直运行良好。在过去 2 周内,日志中开始显示以下错误:

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: 404 page not found

可能是我使用的

"firebase-admin": "^7.3.0"
版本有问题吗?

有人遇到过同样的问题吗?您能否就可能的原因提供一些指导?

firebase google-cloud-platform google-cloud-functions google-oauth firebase-admin
4个回答
3
投票

这看起来像是 NodeJS 的问题,根据 文档,版本 8 不再受支持。 2020 年 12 月 15 日,Firebase CLI 中禁用了将功能部署到 Node.js 8 运行时,这很可能是您面临 404 错误的原因。

要迁移到受支持的较新版本的 NodeJS 运行时,请使用 文档

此外,我不怀疑您的 firebase-admin 版本有任何问题 7.3.0


1
投票

我有同样的错误,但我已经在 Node 12 上了。此外,该函数运行良好多年,现在由于这个原因崩溃了:/

对我有用的唯一解决方案是将管理员身份验证从默认更改为显式传递

service-account.json
,如文档中所述https://firebase.google.com/docs/reference/admin/node/admin。凭证#cert


0
投票

对于部署到 Google Cloud Functions 的用户,要求:

  • 节点 >= 10

初始化:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

0
投票

我也有类似的问题。 节点 > 10

就我而言,错误有时会出现,但并不经常出现 - 我发现的原因是异步执行批量操作。添加await后,调用变得同步,这个问题就消失了。

© www.soinside.com 2019 - 2024. All rights reserved.