Swift: Firebase: How to ensure no one can access my db except my app

自作多情 提交于 2019-11-29 17:02:41

You need to write security rules.

Anyone can see your URL, but security rules are how you dictate who has access to what pieces of data.

These rules act like annotations on your data structure and specify what constraints must be satisfied to allow the read or write.

Let's say you want to secure your database so only authenticated users can access the database. These are the default rules of the Realtime Database.

{
   "rules": {
     ".read": "auth != null",
     ".write": "auth != null"
   }
}

The auth variable a server side value that stores the current authenticated user. The rule checks to see if that variable has a value and therefore contains a logged in user.

I would have expected that the Firebase dashboard allow to generate an API key which I can embed in my app, but that does not seem to be the case.

The Firebase console will give you a secret key, which gives you full access regardless of rules. But if you embed this in your app then it is no longer secure. This is why you use authentication because the this creates tokens against that secret key for the specific logged in user.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!