question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Call to load credentials with FirebaseAdmin does not work

See original GitHub issue

Usually 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
WellspringCScommented, Dec 11, 2019

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!

0reactions
hiranya911commented, Dec 11, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load the default credentials (Firebase function to ...
I had same problem in firebase Error: "Could not get default credentials." Then go to firebase console and go to project setting, where...
Read more >
Add the Firebase Admin SDK to your server - Google
A configuration file with your service account's credentials. If you don't already have a Firebase project, you need to create one in the...
Read more >
Admin Authentication API Errors - Firebase - Google
The credential used to initialize the Admin SDK has insufficient permission to access the requested Authentication resource. Refer to Set up a Firebase...
Read more >
Configuring Firebase Admin SDK with Express
Google recommends that you use the applicationDefault() method to load the firebase-admin credentials path from an environment variable, ...
Read more >
Local development Auth issues with Node.js, Firebase ...
I initialise my app using admin.credential.applicationDefault() , my user has project/owner and Firebase admin roles, and I'm able to make calls ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found