8

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?

Krunal Lia
  • 300
  • 3
  • 13

2 Answers2

4

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

Krunal Lia
  • 300
  • 3
  • 13
3

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

  • Thank you for the response. I saw that the pull request for this fix was merged. Any estimate when this fix will be live? – Krunal Lia Jul 01 '22 at 07:39
  • 1
    Thank you for your patience! This issue should now be fixed in `@firebase/database-compat@0.2.3`, which is a transient dependency of `firebase-admin`. `npm install` should be able to update the dependencies in your environment. We will also update the package.json files in the next Admin Node.js release. – Lahiru Maramba Jul 27 '22 at 18:38