【问题标题】:Firestore security rules that validates in app purchases for userFirestore 安全规则,用于验证用户在应用程序中的购买
【发布时间】:2020-12-26 23:15:48
【问题描述】:

Firestore 应该只允许在应用中购买升级的用户写入和读取数据库。这将如何通过安全规则实现?

目前我正在使用 Cloud Functions 和自定义声明。基本上,当用户购买升级时,Cloud Function 将通过 Google 或 Apple 验证购买,然后相应地设置适当的自定义声明,然后在安全规则中使用。

有没有更好更简单的方法来做到这一点,还是我应该坚持这个设置?

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions firebase-security


    【解决方案1】:

    使用安全规则检查自定义声明非常简单。我不认为你会发现任何事情更容易。

    【讨论】:

    • 是的,这也是我的想法。只是想看看是否有人对此有任何意见,但你是对的。谢谢!
    【解决方案2】:

    在官方documentation,您可以找到有关使用 Admin SDK 验证自定义声明的详细示例,您可以通过不同语言(例如在 python 上)validate the Custom Claims

    # Set admin privilege on the user corresponding to uid.
    auth.set_custom_user_claims(uid, {'admin': True})
    # The new custom claims will propagate to the user's ID token the
    # next time a new one is issued.
    

    此外,此文档包括best practices recommended

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      相关资源
      最近更新 更多