'Google application credentials in azure app service (aspnet core web api)
So I am using Firebase SDK to send push notifications to my android clients.
On local IIS this is how I have configured FirebaseSdk. In Startup.cs I have
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.GetApplicationDefault(),
});
In my web.config I have
<environmentVariables>
<environmentVariable name="GOOGLE_APPLICATION_CREDENTIALS" value="D:\credentials.json" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
</environmentVariables>
this GOOGLE_APPLICATION_CREDENTIALS is what is needed by the Firebase SDK to work.
Now coming to azure I created an environment variable by selecting App Service->Configuration-> New Application Setting
I gave it the path to the file which I had uploaded at the following link
D:\home\site\credentials.json .
I had identified this path using the kudu tool available in the portal. I also confirmed that a variable has been created with kudu by clicking on environment variables.
However I still get this error during deployment
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: One or more errors occurred. (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 https://developers.google.com/accounts/docs/application-default-credentials for more information.) Unable to create an object of type 'DbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Any pointers as to why is my file not being made available to the application?.
Solution 1:[1]
Please use App Configuration under App Services blade menu, this is where you could put your Global Environment Variables just like you would put it in web.config file. You can find out about it from here.
Solution 2:[2]
You need to close the Visual Studio and open it again and do the deployment. i.e. this is due to VS cannot detect the environment variable change on the fly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hassan Raza |
Solution 2 | Sampath |