I have to build an API using Firebase, and need some help with design choices. I want to be able to sell the API to users, who can then use it to build/integrate their own applications. Users will have both read and write privileges.
General information:
- I'm using Firestore db with email & password authentication.
- Only specifically assigned users may use the API
- Each user may only access specific documents concerning them.
I've noticed 3 different ways in which an API can be provided to a user of my Firestore db:
- https triggered cloud functions (https://firebase.google.com/docs/functions/http-events)
- Using the SDK (https://firebase.google.com/docs/firestore/client/libraries)
- Using the REST API provided by Firbase (https://firebase.google.com/docs/firestore/use-rest-api)
API requirements:
- Used only by users that I specifically grant access to (email & password login)
- I want to limit these users to only a couple of read/write tasks that they're able to perform.
- It needs to be safe.
My current approach is:
- Use the 3rd option - the REST API provided by Firebase (thereby giving users the projectId and API key)
- Add authorised users to the list of authorised accounts on Firbase, and limit access using custom claims and database rules.
My questions:
- It seems that https functions (option 1) are normally used in API building. Are options 2 and 3 unsafe?
- What are the normal use cases of the 3 options? When should each be used and when should each be avoided?
- Are there any obvious flaws in my choice of option 3?
- Any other useful information about making these design decisions will be much appreciated.
Thank you in advance