简体   繁体   English

Firebase 安全规则 - Unity

[英]Firebase Security Rules - Unity

I have not implemented Firebase Auth in my application.我没有在我的应用程序中实现 Firebase Auth。 So not able to provide security rules to it.As authentication is neccessary for providing read and write rules.因此无法为其提供安全规则。因为提供读写规则需要身份验证。 Now Firebase is sending Security warnings for it.现在 Firebase 正在为其发送安全警告。 Is there any way that i can dodge these warnings without implementing Auth in my app?有什么方法可以在我的应用程序中不实施 Auth 的情况下避开这些警告? As now it will require many more rework.现在它需要更多的返工。

I get that it can be annoying to implement rules, but there's really no other way to secure your database.我知道实施规则可能很烦人,但实际上没有其他方法可以保护您的数据库。 The moment you share your game with anyone, they'll have enough information to write into your Database.当您与任何人分享您的游戏时,他们就会有足够的信息写入您的数据库。

At this point, there are a few things you can do:此时,您可以做几件事:

1) if you only need to read from the database, you can write something like: 1)如果您只需要从数据库中读取,您可以编写如下内容:

{
    "rules": {
        ".read": true,
        ".write": false
    }
}

And you'd only be able to update it via the console or with the admin SDK (say via Cloud Functions ).而且您只能通过控制台或管理员 SDK (例如通过Cloud Functions )对其进行更新。

2) Anonymous authentication is really easy to do (effectively three lines of code) and would let you get a little more verbose for your rules. 2)匿名身份验证真的很容易做到(实际上是三行代码),并且会让您的规则更加冗长。 This is the rules I use for a game with anonymous authentication (it's a joke "pig clicker" game mimicking "cow clicker", so you can click on one of your pigs to change its color but other users can only see the color of your pig).这是我用于匿名身份验证游戏的规则(这是一个模仿“cow clicker”的笑话“pig clicker”游戏,所以你可以点击你的一只猪来改变它的颜色,但其他用户只能看到你的颜色猪)。

{
  "rules": {
    "pigs": {
      ".read": true,
      ".write": "auth.uid != null"
    },
    ".read": false,
    ".write": false
  }
}

This would make it so you could only write into /pigs/${auth.UserId} , and authentication would be as simple as:这将使您只能写入/pigs/${auth.UserId} ,并且身份验证将非常简单:

var auth = FirebaseAuth.DefaultInstance;
if (auth.UserId == null) {
    await auth.SignInAnonymouslyAsync();
}

Let me know if that helps!让我知道这是否有帮助!

--Patrick ——帕特里克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM