Where to store the JSON file which will be referenced for the environment variable in asp.net hosted on Azure

Viewed 1156

I have created a Web Service using ASP.NET and will be storing data in Firestore. Hence, I will need to set the GOOGLE_APPLICATION_CREDENTIALS environment variable referring to a JSON file. This works locally on my machine, but it doesn't work when it's published to Azure. The problem is I couldn't find the JSON file to locate the file path, I have double checked my local project folder whether the JSON file is in there before publishing. May I know where is the best place to store my JSON file, so that I can locate the file path and GOOGLE_APPLICATION_CREDENTIALS can refer to it in the Azure Portal.

Thank you.

2 Answers

Here's another alternative if you're looking to avoid having that credential file checked into source control or on dev machines, and you already have a secure place to store string configuration data.

You can spin up your Firestore client this way and give it credentials manually:

 var credential = GoogleCredential.FromJson(<JSON AS STRING>);
 var channelCredentials = credential.ToChannelCredentials();
 var channel = new Channel(FirestoreClient.DefaultEndpoint.ToString(), channelCredentials);
 var client = FirestoreClient.Create(channel);

(Code using the Nuget package here: https://www.nuget.org/packages/Google.Cloud.Firestore/)

If your json file is in project when publishing it, it will be uploaded to D:\home\site\wwwroot\xxx.json. You could go to https://yourwebname.scm.azurewebsites.net to find it.

So, you could set the environment variable in Application settings on portal as below:

enter image description here

Related