Firebase - 如何从控制台设置自定义声明 [英] Firebase - how to set custom claim from the console
问题描述
在我的应用程序中,我使用 firebase 身份验证和 Google 帐户作为凭据提供程序.我想为用户分配角色.为了做到这一点,我想向用户在登录期间获得的身份验证令牌添加自定义声明.这是我的问题,因为我不知道如何从 Firebase 控制台向现有用户添加声明.
In my application I use firebase authentication and Google account as credentials provider. I would like to assign roles to users. In order to do it I would like to add custom claims to the authentication token a user gets during login. And here is my problem because I don't know how to add claims to existing user from the firebase console.
推荐答案
目前无法在 Firebase 控制台中为用户设置自定义声明.如果您认为这是一个有用的补充,请提交功能请求.
There is currently no way to set custom claims for a user in the Firebase console. If you think this would be a useful addition, file a feature request for it.
与此同时,添加自定义声明的最简单方法是在终端窗口/命令提示符下使用如下所示的小型 Node.js 脚本执行此操作:
In the meantime the easiest way to add a custom claim is to do so from the a terminal window/command prompt using a small Node.js script like this:
admin.auth().setCustomUserClaims(uid, {admin: true})
另见:
这篇关于Firebase - 如何从控制台设置自定义声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!