0

I'm trying to authenticate to Firebase Firestore on a C# WebAPi 2 hosted in Azure. According to the docs, it's as easy as:

Otherwise, the simplest way of authenticating your API calls is to download a service account JSON file then set the GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to it. The credentials will automatically be used to authenticate. See the Getting Started With Authentication guide for more details.

This works locally on my machine but I can't seem to find a way how to set this environment variable in a Azure WebApp?

Jan Feyen
  • 535
  • 3
  • 13

1 Answers1

0

As Junnas mentioned you can set the App settings, which will act as environment variables.


(source: windows.net)

In Asp.Net 5 there is a build in

Configuration = new Configuration()
             .AddJsonFile("config.json")
             .AddEnvironmentVariables();

Read this blog and this SO

You can find all the predefined environment variables at below link,

https://<yoursitename>.scm.azurewebsites.net/Env.cshtml

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jayendran
  • 9,638
  • 8
  • 60
  • 103
  • Thanks, I came across those as well but they are asp.net 5, our backend is running v2.2 with .NET 4.6.1 The blog you mentioned uses a helper for older Web API versions (which I am using). It's only for reading variables though. I see that System.Environment has Environment.SetEnvironmentVariable("NAME","VALUE") Where value could be the path to the service account JSON file but how do I upload the json file and what path would it be? – Jan Feyen Oct 21 '18 at 08:21
  • still haven't figured out how to do it but found a work around for my problem. 1: Store the JSON file in App_Data folder. 2: create web.config overrides for each environment / developer if the files are different. 3: Get the file from App_Data. var fullPathToGoogleServicesJson = System.Web.Hosting.HostingEnvironment.MapPath($@"~/App_Data/{CoreSettings.FirebaseProjectGoogleServicesJsonFileName}"); pass the file to FirestoreClient – Jan Feyen Oct 21 '18 at 09:24