0

I have not attempted to use the Firebase Admin SDK for some time, so I apologize if this ends up being trivial but I have spent two days on this.

I am creating a new web and mobile app using Firebase, for which I have a data model layer shared between the web and mobile client apps. I want to set up automated testing of the data models using the Firebase Node.js Admin SDK.

So, I followed the instructions here https://firebase.google.com/docs/admin/setup

However, the service account credentials I download from firebase, although it is indeed downloaded as a .json file, the file does not have the form of a JSON file. It is just a long alphanumeric string with an '=' at the end.

As expected, exporting the environment variable ($ export GOOGLE_APPLICATION_CREDENTIALS=...) and then calling useApplicationDefault() results in an unexpected token error.

If I attempt to reconstruct the data type which I think is expected and pull the string in the file into a properly formatted JSON with the key "privateKey", then I get this error: FirebaseAppError: Invalid contents in the credentials file

If I attempt to use the code snippet provided by Firebase on the Service Account page of my project, with the raw unedited non-JSON .json file, I still get unexpected token, as expected, but if I use the edited .json file with the correctly-formatted JSON, I get a PEM error.

FirebaseAppError: Failed to parse private key: Error: Invalid PEM formatted message.

As stated, the .json file Firebase provides to me is not a JSON and only contains an alphanumeric string terminated by an '=' sign.

My edited version has the form

{
    "projectId": "myprojectid-id123",
    "clientEmail": "email@domain.com",
    "privateKey": "abcde1234567890="
}
  • I reinstalled my OS and used a different browser and it downloaded the JSON correctly. So be warned all: it seems the default browser of the Ubuntu-derivative Elementary OS does not correctly download JSON files. I'll let the maintainers of the OS know. This is partly my fault. I like to try new linux distributions on my laptop every month or so in part because it forces me to become a better linux user. It is generally no big deal for me to do so because I have a second storage device and containerize all my development environments. – Anthony De Vellis Apr 09 '22 at 23:07

0 Answers0