Eneris / push-receiver

A library to subscribe to GCM/FCM and receive notifications within a node process.
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
17 stars 16 forks source link

FCM authTokens:generate - possible fix for you #27

Open sdb9696 opened 3 months ago

sdb9696 commented 3 months ago

Hi there,

I was able to use your library as a reference to help me migrate my firebase-messaging python library to the new FCM api. I noticed you have commented out refreshFCMInstallationToken as the requests were failing for you. I was able to get this working in my lib so thought I'd share this with you as you may want to implement it in future.

The way I got mine working was to use a modified url to include installations in front of the fid and also pass the api key in the header. Code snippet is below.

This then returns a new token with a new expiry time. I did wonder though what will happen when the existing token expires. Will it affect the registration token at all or does this just mean that a fresh installation will be required if a new registration token is needed? I'm not sure if you know the answer to this or have any thoughts...

        headers = {
            "Authorization": f"{AUTH_VERSION} {fcm_refresh_token}",
            "x-firebase-client": hb_header,
            "x-goog-api-key": self.config.api_key,
        }
        payload = {
            "installation": {
                "sdkVersion": SDK_VERSION,
                "appId": self.config.app_id,
            }
        }
        url = (
            FCM_INSTALLATION + f"projects/{self.config.project_id}/"
            "installations/{fid}/authTokens:generate"
        )
Eneris commented 1 month ago

Hi. Sorry for such a late reply. I've read it back in August and forgot to answer. Rest asured, I have it on my TODO list. Thanks