Adding authentication

We can't really build an application and call it ready for release unless we at least have some proper authentication. Essentially, we can't trust just anyone with our data, only authenticated users. In Firebase, you can set authentication on the highest level for your database. Click on the Database menu option tab in your admin tool and then select the tab rules. That should showcase the following:

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

Let's highlight the following row:

".read": "auth != null"

In this case, this sets up the read permission for your entire database and we give it the value auth != null. This means that you need to be authenticated to have any kind of read access to the database. You can see in the following row we have the same value, but this time for a rule called .write, which governs the writing access.

This is a good default permission to have. Of course, when testing the database out, you might want to have the value auth == null to shut off authentication, but remember to set the value back to auth != null, or you will leave your database wide open. 

Setting up any kind of authentication means we need to perform some steps, namely:

  • Ensuring the rules are on, that is, auth != null
  • Enabling a security method
  • Adding a user or token (if it is OAuth)
  • Using the AuthService in the application to programmatically log on the user
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset