Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Admin SDK - Error: Credential implementation provided to initializeApp() ... failed to fetch a valid Google OAuth2 access token

I initialized the SDK Admin in my code, but when I call an admin function it complains about credentials and tokens. Any idea what this could be caused by?

var serviceAccount = require('../../../path to the actual json file);
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://<name of my database>.firebaseio.com'
});

Output

Error fetching user data: Error: 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: incorrect header check. Error code: Z_DATA_ERROR".
        at FirebaseAppError.FirebaseError [as constructor] (error.js?8304:42)
        at FirebaseAppError.PrefixedFirebaseError [as constructor] (error.js?8304:88)
        at new FirebaseAppError (error.js?8304:122)
        at eval (firebase-app.js?0db4:121)
like image 262
Eric Almendral Avatar asked Aug 10 '19 11:08

Eric Almendral


1 Answers

The Z_DATA_ERROR suggests that gzip is at fault. Make sure the Firebase Admin SDK has been updated to the latest version.

Also ensure that your computer clock is synchronized.

  • How to Synchronize the Clock in Windows 10 with Internet or Atomic Time
  • How to Synchronize Time with NTP in Linux

And finally, check that the Firebase service account and the database URL are for the same project.

like image 53
Christopher Peisert Avatar answered Sep 22 '22 02:09

Christopher Peisert