push-receiver icon indicating copy to clipboard operation
push-receiver copied to clipboard

FCM authTokens:generate - possible fix for you

Open sdb9696 opened this issue 1 year ago • 1 comments

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"
        )

sdb9696 avatar Aug 29 '24 15:08 sdb9696

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

Eneris avatar Oct 22 '24 09:10 Eneris