在创建用于生成 Firebase CustomToken 的服务器时,我是仅使用服务帐户还是以某种方式在幕后也使用用户凭据?

when creating a server for generating Firebase CustomToken am I using only Service Accounts or somehow behind the scene also User Credentials?

我们即将将该项目投入生产。

1 - 我们的移动应用程序将通过 post 将其发送到我们的内部微服务来创建汇款。这样的 post 请求将 return 从我们的内部 NodeJs 服务器生成的 CustomToken。

2 - 我们的内部微服务会将此类传输复制到 Firestore 并相应地更新其在 Firestore 上的状态。

3 - 代替我们的移动应用轮询或监听我们的内部微服务来获取状态,它将监听 Firestore 以从相应文档获取状态。为了收听,它将在步骤 1 中使用来自 post 的 CustomToken returned。我们公司只想利用来自 Google Firestore 的实时数据库功能来进行此项目(反应式方法) ).

将我正在做的事情与以下语句进行比较时,您是否看到任何 consideration/issue:"Google prefers in most cases that you authorize using a service account"? (从 复制)

CustomToken 是使用此 NodeJs 服务器在内部创建的,并取决于从预期用户提取的 uid authentication/users from Google Firebase

    const admin = require('firebase-admin');

    exports.serviceAccount = {
      "type": "service_account",
      "project_id": "firetestjimis",
      "private_key_id": "ecfc6 ... fd05923",
      "private_key": "-----BEGIN PRIVATE KEY-----\nMIIE .... 5EKvQ==\n-----END PRIVATE KEY-----\n",
      "client_email": "firebase-adminsdk-fg6p9@firetestjimis.iam.gserviceaccount.com",
      "client_id": "102422819688924138150",
      "auth_uri": "https://accounts.google.com/o/oauth2/auth",
      "token_uri": "https://oauth2.googleapis.com/token",
      "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
      "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fg6p9%40firetestjimis.iam.gserviceaccount.com"
    }

     admin.initializeApp({
       credential: admin.credential.cert(exports.serviceAccount)
    });


var uid = "NS .... Ro2"; //copied from https://console.firebase.google.com/project/firetestjimis/authentication/users
var claim = {
  control: true
};
admin.auth().createCustomToken(uid)
  .then(function (customToken) {
    console.log(customToken)
  })
  .catch(function (error) {
    console.log("Error creating custom token:", error);
  });

我们的手机(Angular 中的示例,但 IOS 和 Android 的想法相同)有 SERVICE_ACCOUNT_JSON_FILE 我这样下载:

environment.ts:

export const environment = {
  production: false,
  firebaseConfig: {
    apiKey: "AIzaSy ... 3DCGihK3xs",
    authDomain: "firetestjimis.firebaseapp.com",
    databaseURL: "https://firetestjimis.firebaseio.com",
    projectId: "firetestjimis",
    storageBucket: "firetestjimis.appspot.com",
    messagingSenderId: "795318872350",
    appId: "1:7953 ... 32b26fb53dc810f"
  }
};

app.component.ts

  public transfers: Observable<any[]>;

  transferCollectionRef: AngularFirestoreCollection<any>;

  constructor(public auth: AngularFireAuth, public db: AngularFirestore) {
    this.listenSingleTransferWithToken();
  }

  async listenSingleTransferWithToken() {
    await this.auth.signInWithCustomToken("eyJh ### CUSTOMTOKEN GENERATED FROM INTERNAL NODEJS SERVER ABOVE ### CVg");
    this.transferCollectionRef = this.db.collection<any>('transfer', ref => ref.where("id", "==", "1"));
    this.transfers = this.transferCollectionRef.snapshotChanges().map(actions => {
      return actions.map(action => {
        const data = action.payload.doc.data();
        const id = action.payload.doc.id;
        return { id, ...data };
      });
    });
  }
}

我了解 CustomToken 的创建及其在我们手机上的使用完全依赖于服务帐户。我对吗?我是否错过了一些概念并且我在幕后使用 USER CREDENTIAL 并且在 DEV 环境中正常工作的东西在生产时会弹出一些惊喜?显然这个问题都来自我的免费账户,但在生产中它将是付费账户,但代码和步骤将与这里完全相同。

*** 根据 John 的评论进行编辑

确实 environment.ts 转到浏览器。如果有问题,也许 Angular 有听过 Firestore 文档经验的开发人员可以发表评论

据我所知,您目前创建自定义的方式完全基于服务帐户,以及您对用户 UID 的隐含知识(您从控制台复制的 UID)。您共享的代码中没有其他用户凭据,据我所知,流程的其他部分也没有。

我很想知道您是如何保护此令牌生成的:是什么阻止任何其他 Web 客户端调用您的 listenSingleTransferWithToken 方法或以其他方式从数据库中读取令牌?