Call to load credentials with FirebaseAdmin does not work
See original GitHub issueUsually I post my issues on stack exchange, because I’m assuming the problem is mine. So I’ve done that…
But It occurs to me that on this one maybe I should log a bug. Sure seems to be one. So here’s what I wrote…
I am working with FirebaseAdmin 1.9.1 and attempting to use the recommended method for this call:
FirebaseApp.Create(new AppOptions()
{
Credential = credential,
});
From all that I read, I can load the credential
paramater via this…
var credential = await GoogleCredential.GetApplicationDefaultAsync();
or this
credential = GoogleCredential.FromFile("/your/path/to/glory/google-service-accounts.json");
And if the value of a special environment variable is set as so…
"GOOGLE_APPLICATION_CREDENTIALS": "/your/path/to/glory/google-service-accounts.json",
…the two approaches should produce the same, working, result.
Not so! Not so.
The 2nd version works, but the first, recommended, approach? Using GetApplicationDefaultAsync?
Not so much.
I have checked and re-checked, and the two strings containing “/your/path/to/glory/google-service-accounts.json” are identical, though obviously not the value I’ve pasted here.
GOOGLE_APPLICATION_CREDENTIALS I copied and pasted directly. And I can see it properly set in the environment variables.
In fact, just to add salt to my wounds, I tried this…
credential = GoogleCredential.FromFile(_configuration["GOOGLE_APPLICATION_CREDENTIALS"]);
And the credentials DID load.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Cutting to the point: I did scrutinize that code yesterday, asking the same question. But (in a longer paragraph I started to write to you this morning, I realized I was telling you that
GOOGLE_APPLICATION_CREDENTIALS
was coming in via secrets.Ooops. That’s not environment.
I moved it and… problem solved. Thanks much!
You can see here that the first thing it does is to look up the
GOOGLE_APPLICATION_CREDENTIALS
env variable:https://github.com/googleapis/google-api-dotnet-client/blob/master/Src/Support/Google.Apis.Auth/OAuth2/DefaultCredentialProvider.cs#L84
My guess is that your env variable is not set correctly (or it is not set in a way that is visible to your running process). This causes it to fallback to one of the other credential discovery mechanisms, and ends up finding the wrong credentials.