Control the access of your apps with Firebase
- Create a Firebase Project https://firebase.google.com
- Go to Database options and choice to create a "Realtime Database".
- Go to rules and paste:
{
"rules": {
".read": false,
".write": false,
"$project": {
".read": false,
"$token": {
".read": "data.val() == 1"
}
}
}
}
- Go to Data and import or create an struct like this code:
{
"appName" : {
"tokenCode" : 0
}
}
The tokenCode can be what you want, like the client name.
- If you want to activate an tokenCode, only need put 1 in the value.
You can combine it with my other project autosign to create the unique tokenCode and protect you app from crackers.
- Download and install it:
$ go get github.com/jonathanhecl/controlrun
- Import it in your code:
import "github.com/jonathanhecl/controlrun"
- Setup your Firebase:
controlrun.Set("[ProjectName]", "[appName]/[tokenCode]")
- Control the access:
err := controlrun.Run()
if err != nil {
panic("Permission denied")
}
- Run in a local file or an any test:
hash := controlrun.Set("[ProjectName]", "[appName]/[tokenCode]")
println(hash)
- Copy your hash generated, and use it in the Run() function:
err := controlrun.Run("da39a3ee5e6b4b0d3255bfef95601890afd80709")
if err != nil {
panic("Permission denied")
}