Closed KevinShiCA closed 2 years ago
I just came across the same problem. Looks like this has already been reported: https://github.com/firebase/firebase-admin-go/issues/458#issue-976355243 and fixed, but not yet released
@MaxWaterfall Awesome, nice find! Closing this issue then.
[READ] Step 1: Are you in the right place?
I think so!
[REQUIRED] Step 2: Describe your environment
firebase-tools
is on 9.20.0firebase.google.com/go/v4 v4.6.0
[REQUIRED] Step 3: Describe the problem
I am using firebase for auth + firestore + functions. I recently started migrating from a live development project to a local emulator suite with a fake demo project. My emulators are started using
firebase emulators:start --project demo-test
, such that it does not try to fall back on a real life project when emulators fail.I use the Admin SDK in two different areas on the backend - the first is NodeJS, the second is in Go using
firebase.google.com/go/v4 v4.6.0
. I was successful in getting both backends to target the emulators by setting theFIREBASE_AUTH_EMULATOR_HOST
andFIRESTORE_EMULATOR_HOST
environment variables.In NodeJS, I'm able to initialize the SDK using something like:
I'm not specifying any credentials here, and the
GOOGLE_APPLICATION_CREDENTIALS
environment variable is unset. This works perfectly.In Go, I tried to do the same (in production
GOOGLE_APPLICATION_CREDENTIALS
is set, but not in development):However accessing any of the clients results in an error - the following copy paste is from
fb.Auth()
butfb.Firestore()
does the same:If I set
GOOGLE_APPLICATION_CREDENTIALS
to point to a random service account json file that I had laying around, everything works properly on the Go side, but the emulator starts vomiting out the following warning:I assume this is because the Go SDK has read my random service account file and is sending it in requests to the emulators, which are getting ignored since the emulators are not secure.
Steps to reproduce:
--project demo-test
(project ID is irrelevant, as long as it starts withdemo-
)ProjectID: "demo-test"
in the configFIREBASE_AUTH_EMULATOR_HOST
andFIRESTORE_EMULATOR_HOST
set, the default aslocalhost:9099
andlocalhost:8080
for auth and firestore respectively. Do NOT includehttp://
in these, since the Go library seems to prefix with it automatically.GOOGLE_APPLICATION_CREDENTIALS
to point to the service account fileIMO credentials should not be required when we're targeting emulators, especially since they show warnings when included.
Relevant Code:
Sample go code to run with and without the credentials env var set. The emulator host env vars must be set in all cases.