firebase-admin-node: Firebase fails to fetch a valid Google OAuth2 access token on Windows

  • Operating System version: Windows 10
  • Firebase SDK version: no SDK used
  • Library version: firebase-admin@6.4.0
  • Firebase Product: Realtime database

[REQUIRED] Step 3: Describe the problem

I built a script to download data from the Realtime database, on Mac. Here things work fine. But when tested the script on Windows I get the following error:

@firebase/database: FIREBASE WARNING: {"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: \"Failed to parse access token response: Error: Server responded with status 400.\"."}

Steps to reproduce:

Build a script that access data from Realtime database, using firebase-admin. Run it on Windows.

Relevant Code:

var admin = require("firebase-admin");
var serviceAccount = require("./adminsdk.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://<project-id>.firebaseio.com"
});
var db = admin.database();
var dataRef = db.ref("ref");

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

i am experiencing the same issue but when i am running my Nodejs application in a docker container.

@firebase/database: FIREBASE WARNING: {"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: Error while making request: getaddrinfo EAI_AGAIN accounts.google.com:443. Error code: EAI_AGAIN\"."}

clocks is synced, is there anyone with the same issue as me ?

Possible causes include:

  1. Clock out of sync (most likely, since you’re only seeing this on one environment)
  2. Service account and the database URL are for 2 different projects

Please use Stackoverflow if you wish to follow up with further questions.

Just for reference in case someone is looking for a solution:

One of my students was having this issue with Windows (WSL). Indeed the error was a clock out of sync, but Windows clock was ok. The problem was that the Linux clock (WSL) was out of sync. You can verify if it’s your case with the date command in your terminal.

If it’s actually out of sync try this:

~$ sudo hwclock -s

Hope it helps 👍

My problem was solved sending the data as a miltipart form instead of a json. Forcing us to not use json in node… Wtf.

I am having this issue too and im not having a clue of where to start to solve it.

@hiranya911 How did you fix the clock sync error?

@hiranya911 it worked. Thank you!