Cloud function that runs in Firebase to authenticate IoT controller
- Install firebase-tools:
npm install -g firebase-tools
- Run
(cd functions && npm install)
- Deploy to Firebase with
firebase deploy
Every Green Garden IoT controller has a unique serial number that is visible to the user, but a way is needed to verify if the serial number was generated by the project group/product owner or not.
The file functions/src/secrets.ts
contains two secret strings that are used by the owner to sign serial numbers:
PASSWORD
: The password that unlocksSIGNING_KEY
SIGNING_KEY
: This key is combined with the serial number in a hashed JSON object
Example: { serial: "X", signingKey: "Y" }
becomes 1f16d2ed0944646e26359c96408bc8c151beb46f
.
The combination of serial number and unique key for the backend works like an email and password does for the frontend. It gives the smart garden access to everything in the database under /garden/{serial}
. This ensures that every garden can only access its own data instead of giving the IoT controller admin access to the whole database.