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="
}