Hi,
I am using Google.Cloud.Firestore for my asp.net project, but i got this error =
"System.InvalidOperationException: 'The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/"
My question is how to authenticate the Firestore library to make request.
Please tell us how you're trying to authenticate. Do you have the environment variable set as described?
This is my question, how i can authenticate to use this library in my project?
Download a service account JSON file and then set the environment variable to point to it. See https://developers.google.com/identity/protocols/OAuth2ServiceAccount
Doesn't work for me, give me same error.
i did like that
PM> set GOOGLE_APPLICATION_CREDENTIALS="C:\Users\hussa\Source\Repos\WebSite1\WebSite1\app-4c5552adf3.json"
is there away to pass the GoogleCredential to the firestore library?
Setting it from a command prompt won't affect the environment used by ASP.NET. You need to set the ambient environment variables.
how to do that in visual studio ? can you explain please ?
(Handling an explicit credential is awkward at the moment - you have to create a channel, then a client from that, then pass the client to FirestoreDb.Create.)
used With Powershell:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\hussa\Source\Repos\WebSite1\WebSite1\app-4c5552adf3.json"
still same error
Set the environment variable in the Windows environment settings instead.
And are you actually running as that user? (We don't have any context of how you're running this.) If you're getting that error, the environment variable isn't set as far as the code is concerned. I suggest you add some logging of the environment variable right at the start of your app.
I'm afraid I can't help any more on this issue without more information - please see my previous comment.
(To avoid stale issues cluttering up github, I'll close this in about a week if there are no further replies. You could still reply later at which point I'd potentially reopen the issue, of course.)
Closing as stale.
Seems this thread died, but for anyone else like me drowning in the docs and coming accross this thread, here is what I had to do to make it work:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "app-c5a5afc0d7e5.json");
FirestoreDb = FirestoreDb.Create(Config["firestore:projectid"]);
I had the same workaround as @peetjvv, came here hoping for another answer. I did find this related issue though: https://github.com/googleapis/google-cloud-dotnet/issues/1576
The approach by @peetjvv works for me, when I call FirebaseDB.Create once.
However, when I later change the environment variable and create another DB, I get "failed permissions" because they create functions seems to still keep the old credential.
Any idea how to fix this?
@h4rm: The default credentials are cached when they're first loaded. Changing the environment variables within a single process won't help. If you run a second time, it should be fine.
If you need to use two different sets of credentials within the same process, you'll need to use custom credentials - create a FirestoreClient as per https://googleapis.github.io/google-cloud-dotnet/docs/faq.html#how-can-i-use-non-default-credentials-for-grpc-based-apis and then create a FirestoreDb with that client.
We're working on making it much easier to use custom credentials, but I don't expect that to be available in the Firestore library very soon.
This was quick, thanks a lot @jskeet. I am going with the custom credentials then!
Most helpful comment
Seems this thread died, but for anyone else like me drowning in the docs and coming accross this thread, here is what I had to do to make it work: