After Firebase has deprecated the Instance ID API, we had to re-implement the subscription mechanism for all our users.
It is no possible anymore to pass subscriber auth data in exchange for a FCM token. Instead, we were forced to use Firebase Javascript SDK methods to get the token.
Idea
The idea is pretty simple as it was on the early stages of the project. We need to investigate how Javascpript SDK works and how we can use it to get the same mechanism on the server side.
Pros:
- no additional heavy dependencies in client’s code (code snippet)
- solution will work regardless of current Firebase status (all failed requests will be postponed and retried on our servers)
- more control over the subscriber’s data and its lifecycle (refresh tokens, etc.)
- instant updates deployment (no need to update the script and wait for users cache to expire)
Cons:
- more code to maintain
- a regular Firebase SDK updates monitoring is required
- the whole approach does not seem to be promoted by Firebase in any way. APIs docs are difficult to be found and understood
- affects the overall website performance (additional requests, additional JS code)
- a possibility of rate limits and thersholds
Logic
An updated mechanism is now consists of the following steps:
- Firebase installation ID is generated by SDK once the user visits the website
- installation is then being registered on firebaseinstallations.googleapis.com (with X-Goog-Api-Key header and some required payload provided)
- auth token is being returned in the response
- auth token is then being used in headers to exchange subscriber’s auth data for a FCM token by requesting
https://fcmregistrations.googleapis.com/v1/projects/.../registrations:generateToken
Needs to be done
- receive and store FID from the client
- implement google installations API requests
- obtain firebase installation auth token every time we’re about to request a FCM registration API
- update
assistantservice to have an access to a newconfigobject whereX-Goog-Api-Keyshould be stored - update endpoints to request FCM tokens