5

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.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
vomoxon
  • 63
  • 5
  • How are you hosting your application ? Are you using Azure App services ? If yes then declare it in "Application Settings" . Any thing declared in Application Setting in Azure App services can be accessed like environment variables – Imran Arshad Dec 18 '18 at 04:49

2 Answers2

4

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/)

Veatch
  • 893
  • 7
  • 11
0

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

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Hi, sorry for the late reply. I found out the problem was I did put the json file into my folder, but then I did not refresh it in my VisualStudio, so the file was not even there when I published to Azure, lol. But thanks! – vomoxon Jan 19 '19 at 21:30