我有一个包含的appid的有效载荷,以确定第三方应用程序的自定义标记。
我想验证读取/写入我的数据是这样的:
/apps
集合这个答案,我最终偶然发现,是相当不错的,但也可能得到改善。
我所要做的就是正确识别我给自定义标记的有效载荷的第一件事情 - 因为我在使用云服务功能,生成有效载荷(graphcool),我的有效载荷是default: { appid }
,而不是仅仅appid
。从那里,只是在一些权限重新措辞已经足够使用我会想象当前规则succeessdully验证:
service cloud.firestore {
match /databases/{database}/documents {
match /sampleData/{type}/{appName}/{record} {
allow read: if isSignedIn() && isValidApp(database) && ownsExisting() && appIdInExisting()
allow write: if isSignedIn() && isValidApp(database) && ownsPayload() && appIdInPayload()
}
// functions
function isSignedIn () {
return request.auth != null
}
function isValidApp (database) {
return exists(/databases/$(database)/documents/apps/$(request.auth.token.appid))
}
function ownsExisting () {
return resource.data.uid == request.auth.uid
}
function ownsPayload () {
return request.resource.data.uid == request.auth.uid
}
function appIdInExisting () {
return resource.data.app_id == request.auth.token.appid
}
function appIdInPayload () {
return request.resource.data.app_id == request.auth.token.appid
}
}
}
有人可能会做的更好,虽然。
我以为我可以得到至少前两个自己:
service cloud.firestore {
match /databases/{database}/documents {
match /sampleData {
allow read: if isSignedIn() && isValidApp() && ownsExisting() && appIdInExisting()
allow write: if isSignedIn() && isValidApp() && ownsPayload() && appIdInPayload()
}
// functions
function isSignedIn () {
return request.auth != null
}
function isValidApp () {
return get(path('apps')).data.child(request.auth.token.appid).exists()
}
function ownsExisting () {
return resource.data.uid == request.auth.uid
}
function ownsPayload () {
return request.resource.data.uid == request.auth.uid
}
function appIdInExisting () {
return resource.data.app_id == request.auth.token.appid
}
function appIdInPayload () {
return request.resource.data.app_id == request.auth.token.appid
}
}
}
/apps
呼吁1号文件“样本的应用ID”与“样品APP-ID” ID和name字段......但在我的令牌使用这不起作用:FirebaseError: Missing or insufficient permissions
我通过我的服务器上这个功能生成令牌:
var FirebaseAdmin = require('firebase-admin')
var serviceAccount = require('./firebase-service-credentials.json')
var claims = require('./custom-token-claims') // {appid: 'sample-app-id'}
let credential = FirebaseAdmin.credential.cert(serviceAccount)
FirebaseAdmin.initializeApp({ credential })
const generateTokenWithPayload = async id => {
try {
const token = await FirebaseAdmin.auth().createCustomToken(id, claims)
return { data: { token } }
} catch (err) {
return { error }
}
}
module.exports = async event =>
await generateTokenWithPayload(event.data.userIdentifier)
并在发布前,我在签约 - 这部分我可以验证似乎是工作,因为我看到我验证了新的非匿名用户 - >用户选项卡中的火力控制台:
— Feb 11, 2019 Feb 11, 2019 smaple-user-id
这本质上是客户端代码:
await firebase
.auth()
.signInWithCustomToken(token)
.catch(console.error)
const db = await firebase.firestore()
db.collection(path + this.state.appName).add(payload)
我张贴与架构{app_id, app_name, date, metric, uid}
到的sampleData记录/度/样本应用程序名称/ {自动生成}
request.auth.token.appid
因为我用request.auth.token.default.appid
的export default
instead应modules.export
这个答案是相当不错的,但也可能得到改善。
我所要做的就是正确识别我给自定义标记的有效载荷的第一件事情 - 因为我在使用云服务功能,生成有效载荷(graphcool),我的有效载荷是default: { appid }
,而不是仅仅appid
。从那里,只是在一些权限重新措辞已经足够使用我会想象当前规则succeessdully验证:
service cloud.firestore {
match /databases/{database}/documents {
match /sampleData/{type}/{appName}/{record} {
allow read: if isSignedIn() && isValidApp(database) && ownsExisting() && appIdInExisting()
allow write: if isSignedIn() && isValidApp(database) && ownsPayload() && appIdInPayload()
}
// functions
function isSignedIn () {
return request.auth != null
}
function isValidApp (database) {
return exists(/databases/$(database)/documents/apps/$(request.auth.token.appid))
}
function ownsExisting () {
return resource.data.uid == request.auth.uid
}
function ownsPayload () {
return request.resource.data.uid == request.auth.uid
}
function appIdInExisting () {
return resource.data.app_id == request.auth.token.appid
}
function appIdInPayload () {
return request.resource.data.app_id == request.auth.token.appid
}
}
}
有人可能会做的更好,虽然。