简体   繁体   English

azure 应用服务中的谷歌应用凭证(as.net core web api)

[英]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?.关于为什么我的文件不能用于应用程序的任何指示?

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.请使用应用服务刀片菜单下的应用配置,您可以在此处放置全局环境变量,就像将其放入 web.config 文件中一样。 You can find out about it from here .您可以从这里了解它。

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.

相关问题 .NET核心Web API作为Azure应用程序服务上的虚拟应用程序 - .NET core web API as virtual application on Azure app service 如何在单个应用程序服务上部署ASPNET Core Web API和ASPNET WebAPI - How to deploy aspnet core web api and aspnet webapi on single app service 使用.net核心Web应用程序项目在Azure中开发和部署API应用类型的App服务 - Develop and deploy App service of type API app in Azure using .net core web application project 将.NET Core 2.0 Web应用程序发布到Azure App Service时出错 - Error publishing .NET Core 2.0 web application to Azure App Service 将.Net Core 3.0 Web API 部署到 Azure 应用服务时出错 - Error deploying .Net Core 3.0 Web API to Azure App Service 带有应用服务 Web 应用的 Azure 应用程序网关 - Azure Application Gateway with App Service Web App Azure App Service上的AspNet Core达到100%的CPU峰值并且App Gateway负载均衡器不起作用 - AspNet Core on Azure App Service peaks to 100% CPU and app gateway load balancer not working 由于无法找到GOOGLE_APPLICATION_CREDENTIALS文件,因此无法在Azure App Service上进行Google Cloud Vision反向图像搜索 - Google Cloud Vision reverse image search fails on Azure App Service because GOOGLE_APPLICATION_CREDENTIALS file cannot be found 如何在Azure Web App的ASPNET Core App中运行jsreports.net - How to run jsreports.net in aspnet core app in azure web app 在不传递用户凭据的情况下保护 Azure 应用服务 API 调用 - Securing Azure App Service API calls without passing user credentials
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM