firebase - 如何仅将具有查看者权限的新用户添加到 console.firebase 项目中的特定应用程序
问题描述
我只能在 console.firebase.google.com 上为项目添加一个新用户,以访问它拥有的所有应用程序。我想限制用户从项目中授予特定应用程序的权限,而不是为应用程序创建新项目。这可行吗?
解决方案
此行为不是内置的,因为应用程序是为项目的版本控制而设计的。但是,您可以通过对用户使用自定义声明来实现这一点。这确实需要安装计费帐户和 Cloud Functions。但是在注册时,您可以在完成时调用云函数,该函数将调用云函数以向用户添加自定义声明。
例如
exports.setApp= functions.https.onCall((data, context) => {
if(!data.app && ! context.auth) return;
if(!["appName1","appName2"].includes(data.app)) return;
return admin
.auth()
.setCustomUserClaims(context.auth.uid, { app: data.app})
.then(() => {
// The new custom claims will propagate to the user's ID token the
// next time a new one is issued.
});
// ...
});
完成此操作后,您必须在完成时刷新用户令牌以确保 id 令牌具有更新的声明。
您可以在此处阅读有关此内容的更多信息:https ://firebase.google.com/docs/auth/admin/custom-claims
推荐阅读
- java - 查询所有文档中的字段并确定该字段在哪个文档中找到?
- go - 需要与 Makefile 一起使用多个 Go 版本
- swift - 在 ForEach 循环中增加变量(SwiftUI)
- javascript - 使用 Nuxt.js 选择网站框架的初学者
- python - 在 AWS 上运行 Python 脚本并将 5GB 的文件传输到 EC2
- javascript - Webpack 开发服务器重新加载但不显示标记或 CSS 更改?
- php - 未定义变量 - Wordpress 中的 PHP 代码片段
- python - TypeError:“NoneType”类型的对象没有 len(),空变量?
- ios - 为什么在主线程上调用事物是程序员的责任?
- python - 熊猫 - value_counts() 中的消失值