Missing `client_secret` when running offline tests using firebase-functions-test

Viewed 378

I am using firebase-functions-test to unit test my cloud functions. The test is configured to run an offline test, but still, when accessing the test firestore, I get an authentication error: Failed to parse refresh token file: Error: Refresh token must contain a "client_secret" property.. What can cause this?

1 Answers

After digging in the code of firebase-functions-test and firebase-admin, when initializing firebase-functions-test for offline mode, it still uses the gcloud application default credentials. If you have ever installed and used gcloud, this lives in ~/.config/gcloud/application_default_credentials.json.

I had a setup from an old project on GCP that was logged in as a service account instead of an authenticated user, hence I had the default credentials setup, but it did not contain the client_secret required by firebase-admin. I simply logged for application default with gcloud auth application-default login. This solves the issue.

Still a bit baffled by the fact that the offline mode requires authentication. I haven't tested with an invalid, yet correctly formatted application default credentials.

Related