[英]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.所以我正在使用 Firebase SDK 向我的 android 客户端发送推送通知。
On local IIS this is how I have configured FirebaseSdk.在本地 IIS 这就是我配置 FirebaseSdk 的方式。 In Startup.cs I have在 Startup.cs 我有
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.GetApplicationDefault(),
});
In my web.config I have在我的 web.config 我有
<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.这个GOOGLE_APPLICATION_CREDENTIALS是 Firebase SDK 工作所需要的。
Now coming to azure I created an environment variable by selecting App Service->Configuration-> New Application Setting现在来到 azure 我通过选择 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.我使用门户中提供的 kudu 工具确定了这条路径。 I also confirmed that a variable has been created with kudu by clicking on environment variables.我还通过单击环境变量确认已使用 kudu 创建了一个变量。
However I still get this error during deployment但是我在部署期间仍然收到此错误
An error occurred while accessing the Microsoft.Extensions.Hosting services.访问 Microsoft.Extensions.Hosting 服务时出错。 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'. (应用程序默认凭证不可用。如果在 Google Compute Engine 中运行,则它们可用。否则,环境变量 GOOGLE_APPLICATION_CREDENTIALS 必须定义为指向定义凭证的文件。请参阅https://developers.google.com/accounts/docs /application-default-credentials以获取更多信息。)无法创建类型为“DbContext”的 object。 For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728
Any pointers as to why is my file not being made available to the application?.关于为什么我的文件不能用于应用程序的任何指示?
You need to close the Visual Studio and open it again and do the deployment.您需要关闭 Visual Studio 并再次打开它并进行部署。 ie this is due to VS cannot detect the environment variable change on the fly.即这是由于 VS 无法即时检测到环境变量的变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.