简体   繁体   English

一个 Gmail 帐户可以访问 Firebase Admin SDK 中具有不同自定义声明的两个应用吗

[英]Can One Gmail Account Has Access to Two Apps with different Custom Claims in Firebase Admin SDK

I want to ask about Firebase Admin SDK in case for using Custom Claim between two related apps: Server App and Client App.我想询问 Firebase Admin SDK,以防在两个相关应用程序之间使用自定义声明:服务器应用程序和客户端应用程序。 Each of them has different features.他们每个人都有不同的特点。 They are all placed inside the same Firebase project, but using different collection.它们都放置在同一个 Firebase 项目中,但使用不同的集合。 Both apps are using Cloud Function which have different file of Node.js.这两个应用程序都使用具有不同 Node.js 文件的 Cloud Function。 I put all the Cloud Function codes in different project of Visual Studio Code.我将所有 Cloud Function 代码放在 Visual Studio Code 的不同项目中。

For example in this code for Server App:例如,在 Server App 的代码中:

 claims = { serverFeatureA: true, serverFeatureB: false, }; admin.auth().setCustomUserClaims(uid, claims);

And this is for Client App:这是针对客户端应用程序的:

 claims = { clientFeatureA: true, clientFeatureB: false, }; admin.auth().setCustomUserClaims(uid, claims);

What I am worrying is if the same Gmail account uses these both apps and Cloud Function assigns its claims for different features?我担心的是,如果同一个 Gmail 帐户同时使用这两个应用程序并且 Cloud Function 将其声明分配给不同的功能? Will this overwrite the old claims written in Client App and only exist in Server App if user subscribed to Client first, then Server?如果用户先订阅客户端,然后订阅服务器,这是否会覆盖客户端应用程序中编写的旧声明并且仅存在于服务器应用程序中? Any help will be great.任何帮助都会很棒。 Thanks.谢谢。

Since you have only ONE Firebase project (which means one set of users declared in the authentication service of this Firebase project), when one of your Cloud Functions updates the Custom Claims assigned to a user of this project it overwrites the Custom Claims previously set for this user (independently of the Cloud Function that previously set the Claims).由于您只有一个Firebase 项目(这意味着在此 Firebase 项目的身份验证服务中声明的一组用户),因此当您的一个 Cloud Functions 更新分配给此项目用户的自定义声明时,它会覆盖之前设置的自定义声明此用户(独立于先前设置声明的云功能)。

What you can do to avoid that is to check, in each of your Cloud Functions, that the user that is going to be updated does not hold the Claims of the other profile.您可以做些什么来避免这种情况,即在您的每个 Cloud Functions 中检查要更新的用户是否不持有其他配置文件的声明。 In other words, prior to assign a Server App claim to a specific user you check that this user does not have the Client App claim, and vice-versa.换句话说,在将服务器应用程序声明分配给特定用户之前,您检查该用户是否没有客户端应用程序声明,反之亦然。

The code to do so depends on your Cloud Function trigger type and code.执行此操作的代码取决于您的 Cloud Function 触发器类型和代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM