firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
367 stars 131 forks source link

Cannot initalize with FIREBASE_CONFIG environmental variable #246

Closed vanpyrzericj closed 4 years ago

vanpyrzericj commented 4 years ago

Per the documentation here in the section Initialize without parameters, I expect to be able to call

FirebaseApp.Create();

and provide the contents of my Firebase service account JSON file in the environmental variable called FIREBASE_CONFIG. However, upon running my application, the following exception is thrown:

System.InvalidOperationException: 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.

So is the documentation wrong? It seems to still be expecting me to set GOOGLE_APPLICATION_CREDENTIALS.

Is the only way to provide the service account credentials through a file and I cannot directly pass the contents of said file when I want to initialize it?

hiranya911 commented 4 years ago

FIREBASE_CONFIG is not a way to specify credentials. It is in addition to Google Application Default Credentials.

The SDK can also be initialized with no parameters. In this case, the SDK uses Google Application Default Credentials and reads options from the FIREBASE_CONFIG environment variable.

Meaning you must set GOOGLE_APPLICATION_CREDENTIALS to point to the service account JSON file, and use Firebase FIREBASE_CONFIG to specify any remaining Firebase options (database URL, storage bucket, project ID etc). Also note that:

  1. Google Application Default Credentials is a feature provided by the underlying Google API Client libraries. They only support specifying a file path in GOOGLE_APPLICATION_CREDENTIALS.
  2. C# Admin SDK doesn't support RTDB and Cloud Storage yet. So only projectId can be set via FIREBASE_CONFIG today. Anything else is effectively ignored.