【发布时间】:2018-07-12 13:03:51
【问题描述】:
admin.auth().verifyIdToken(tokenId)
.then((decoded) => res.status(200).send(decoded))
我了解verifyIdToken() 可以验证来自 Firebase 身份验证客户端的用户 ID 令牌。但是,我们需要通过确保数据库查询受到为令牌中标识的用户定义的数据库安全规则的限制来保护我们的云功能。鉴于默认情况下 admin SDK 具有无限访问权限,我如何将其访问权限限制为仅经过身份验证的用户的访问权限?
【问题讨论】:
-
您能否编辑您的问题以解释“保护”功能的含义?这有点模糊。
-
我们要确保我们的http trigger api端点的数据库读/写访问遵循firebase中的database-rules.json。
-
我们的第一次尝试是在我们的 http 触发器 API 中的一些 get/update/set/remove 访问中使用 firebase web(使用令牌登录)而不是 firebase admin。它有效,但不可扩展。
-
我很想知道什么是不可扩展的? (这绝对不是最好的解决方案,但你在测量什么?)
-
` const firebase = require('firebase'); const userGet = (validFirebasePath) => firebaseDatabase .database() .ref(validFirebasePath) .once('value') .then(snapshot => snapshot.val()); export.apiHandler = (request, response) => { // 我们从请求中获取 accessToken getCustomToken(accessToken) .then((customToken) => firebase.auth().signInWithCustomToken(customToken) .then(() => userGet ('users/userA')) .then(data => response.json(data)) }; ` 这是我们的第一次尝试。
标签: javascript firebase firebase-realtime-database firebase-authentication google-cloud-functions