gpt4 book ai didi

firebase - 使用 Firebase 进行 secret URL 身份验证

转载 作者:行者123 更新时间:2023-12-02 19:46:24 24 4
gpt4 key购买 nike

我有一个使用 Firestore 和 Cloud Functions 的客户端 Web 应用。

我想设置规则,以便如果用户拥有文档的 secret URL,则该用户可以写入该文档,而无需任何其他类型的登录或身份验证。像(伪代码,我刚刚编写的request.params.secret_token):

service cloud.firestore {
match /databases/{database}/documents {
match /cities/{city} {
allow read, write: if resource.data.secret_token == request.params.secret_token;
}
}
}

我对各种可用的身份验证选项感到困惑,无法完全推理出最佳的前进方式。

感觉接近的潜在选项:

  • Anonymous authentication可能需要,这可以让我获得一个身份验证 token 。据我所知,如果没有其中之一,我就走不了多远。
  • 使用 custom claim ,但它说您只能在服务器端安全地设置它们。
  • 使用 custom token ,但是当我有一个预先存在的登录服务器组件时,这似乎更适用。

最佳答案

if a user has a secret URL for a document that user is able to write to it, without need any other kind of login or authentication.

只需设置数据库规则,即可允许任何人在该特定网页上的 JavaScript 中指定的路径处读取和/或写入数据。也许只是简单地将数据库读取或写入放在 <script> 中在你的 Firebase 之后标记 <script>标签就在该页面中。

但是,正如您所说,访问该页面/URL 的任何人都将能够读取和/或写入该特定节点、字段或文档中的任何数据。

像这样编辑 firestore.rules 文件以启用任何人/所有人的读写。 See Documentation .

service cloud.firestore {
match /databases/{database}/documents {
match /<some_path>/ {
allow read, write;
}
}
}

关于firebase - 使用 Firebase 进行 secret URL 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49470875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com