执行Firebase应用检查后,如何从Nodejs Admin SDK访问Firebase数据库

发布于 2025-02-10 18:58:20 字数 1090 浏览 1 评论 0原文

我已经启用了 firebase应用程序检查在我的项目中,以确保所有请求仅来自我们的应用程序。到目前为止,这一直运行良好(使用Recaptachav3作为Web的证明提供商)。但是,我想从我的后端nodejs服务器访问数据库(RTDB)。我正在使用带有服务帐户的Firebase-Admin-SDK。但是我无法做到。

const { initializeApp, applicationDefault } = require('firebase-admin/app');
const { getDatabase } = require('firebase-admin/database');

const app = initializeApp({
  credential: applicationDefault(),
  databaseURL: '********',
});

const db = getDatabase(app);

const ref = db.ref('/some-path');
ref.once('value', (snapshot) => {
  console.log(snapshot.val());
});

下面的错误是付出

[2022-06-27T09:42:25.299Z] @firebase/database:firebase警告:缺少appCheck token(https://qtalkproject.fire.firebaseio.com/

)仅检查客户? Firebase不应该允许所有来自服务帐户的请求吗?为什么要要求应用程序检查令牌? acc到 documentation 允许firebase-admin-sdk创建应用程序检查令牌。如果允许创建应用程序检查令牌,是否意味着它已经被认证?为什么我不能从同一admin SDK访问数据库?我在这里错过了什么吗?

I have enabled Firebase App Check in my project to ensure all requests are coming only from our app. That has been working well till now (Using RecaptachaV3 as a Attestation Provider for web). However I want to access the database (rtdb) from my backend nodejs server. I'm using the firebase-admin-sdk with a service account for it. But I am unable to do it.

const { initializeApp, applicationDefault } = require('firebase-admin/app');
const { getDatabase } = require('firebase-admin/database');

const app = initializeApp({
  credential: applicationDefault(),
  databaseURL: '********',
});

const db = getDatabase(app);

const ref = db.ref('/some-path');
ref.once('value', (snapshot) => {
  console.log(snapshot.val());
});

Below error is thrown

[2022-06-27T09:42:25.299Z] @firebase/database: FIREBASE WARNING: Missing appcheck token (https://qtalkproject.firebaseio.com/)

Isn't app check only for clients? Shouldn't firebase allow all requests that are coming from a service account? Why is it asking for an app check token? Acc to the documentation the firebase-admin-sdk is allowed to create app check tokens. If it is allowed to create app check tokens, doesn't it mean it is already authenticated? Why can't I access the database from the same admin sdk then? Am I missing something here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

本宫微胖 2025-02-17 18:58:20

如果其他任何人都像我一样被阻止,直到firebase发布修复程序,则可以使用较旧版本的firebase admin sdk,该版本没有应用程序检查(我使用v9.3.0)来访问RTDB和其他Firebase功能

If anyone else is blocked like me until firebase releases the fix, you can use the older version of the firebase admin sdk which doesn't have app check (I used v9.3.0) to access rtdb and other firebase features

顾挽 2025-02-17 18:58:20

firebaser在这里

您是正确的,Firebase Admin SDK应绕过应用程序检查。感谢您查找和报告此错误!我们的团队已经确定了这个问题,目前正在进行解决方案。我们将使用以下github问题来跟踪进度 https://github.com /firebase/firebase-admin节点/问题/1788

Firebaser here

You are correct, the Firebase Admin SDK should bypass App Check. Thank you for finding and reporting this bug! Our team has identified the issue and currently working on a fix. We will use the following GitHub issue to track the progress https://github.com/firebase/firebase-admin-node/issues/1788

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文