1

I am using Google.Cloud library for c#, and I want to get data from my Firestore database. I want to use JSON key, but I dont want to put it to GOOGLE_APPLICATION_CREDENTIALS variable.

my json Key is stored in C# variable

string jsonKey = ...;

project id is stored in other variable:

string projectId = ...;

How to do it.

2
  • Could you clarify exactly what you mean by "json key"? Do you mean the content of a service account credential, or the path to that as a file, or something else? Commented May 3, 2022 at 9:05
  • jsonKey is a string which stores full json key, not a path to json file. This json key has all informations needed to login to Firestore database. Commented May 4, 2022 at 15:22

1 Answer 1

2

If you've got the full service account credential JSON in jsonKey, then you just need:

var firestoreDb = new FirestoreDbBuilder
{
    ProjectId = projectId,
    JsonCredentials = jsonKey
}.Build();

Basically each "client" type (in this case FirestoreDb) provides a corresponding builder class which is intended to make it easy to provide everything you need. (In the next major version, to be released fairly soon, this will also provide integration with Microsoft.Extensions.DependencyInjection.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.