如何处理多个Firebase项目服务器端?

时间:2019-07-20 05:36:04

标签: .net firebase flutter firebase-admin

我有一个需要4个移动应用程序(在Flutter中内置)的SaaS应用程序:

  • 客户应用的iOS / Android版本
  • iOS / Android版本的管理应用

最初,我当时想将所有4个应用程序都驻留在一个Firebase项目中,但是我已经读到这可能不是处理问题的最佳方法(Firebase FCM, multiple apps in the same firebase project)。

将它分解成两个Firebase项目,一个用于客户应用程序,一个用于管理应用程序,我没有问题,但是当我的API要发送推送时,如何处理该服务器端呢?

服务器正在使用.Net,现在我正在使用Global.asmx创建Firebase实例:

protected void Application_Start(object sender, EventArgs e)
{
    // Enable firebase
    FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/customerapp-245105.json")).CreateScoped("https://www.googleapis.com/auth/firebase.messaging") });
}

但这只会启用客户应用程序吗?我还如何创建管理应用程序?

我以为我做不到:

protected void Application_Start(object sender, EventArgs e)
{
    // Enable firebase
    FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/customerapp-245105.json")).CreateScoped("https://www.googleapis.com/auth/firebase.messaging") });

    FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/adminapp-244405.json")).CreateScoped("https://www.googleapis.com/auth/firebase.messaging") });
}

而且,在网络服务中调用实例时如何区分实例?因为第一个实例将在向客户发送推送时使用,第二个实例用于管理员?

1 个答案:

答案 0 :(得分:0)

每个FirebaseApp实例必须被赋予唯一的名称。您可以通过实例名称查找实例。请参阅文档中的示例:https://firebase.google.com/docs/admin/setup#initialize_multiple_apps