Skip to content

Asp.Net Core Firebase Environment Variable Read Problem on Linux Ubuntu

Firebase now supports Asp.Net core, or say .Net core for it’s database operations. There is a new Nuget package which gives you ability to use firebase from backend server usng C#. Although only cloud firestore, which is in beta version at time of writing this post, is supported. For storage, you will still need javascript library.

Recently i was using Firebase cloud Firestore in a application. It requires to set GOOGLE_APPLICATION_CREDENTIALS environment variable. While developing you can easily set it in Visual Studio. Problem comes when you deploy it on production and instantly get this error “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 for more information.“.

Even if you try to add this environment variable in /etc/environment location, when you will run the app from server, you will still get this error.

However i spent hours and finally got the solution.

My production environment is Ubuntu 16.04 with supervisor installed to run core. I have added environment variable from the supervisor config file. Now to read GOOGLE_APPLICATION_CREDENTIALS, just add it in supervisor config file, and you are good to go. Like this:

environment=GOOGLE_APPLICATION_CREDENTIALS=/path to your secret file.json

After that just restart supervisor, and you app will work correctly. For more information on how to setup supervisor config file, read my earlier post on core hosting. I am not sure about the security concerns, but i will update this post if i will find any.

If you have any question or feedback, let me know via comments.

Be First to Comment

Leave a Reply

Your email address will not be published.