4

I've been reading on canonical IDs in GCM and how they help to rectify sending duplicate push notifications and with security. But now with Firebase Cloud Messaging (FCM), does this issue still exist?

I am the registration part has been taken away from the developer now and we just wait for a token refresh as per below:

    public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    @Override
    public void onTokenRefresh() {
        // Get updated registration ID
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Logger.d("Refreshed FCM token: " + refreshedToken);
    }
}

Some info on canonical IDs can be found here.

AL.
  • 36,815
  • 10
  • 142
  • 281
j2emanue
  • 60,549
  • 65
  • 286
  • 456

1 Answers1

5

Update:

I recently revisited this topic on Canonical IDs and have concluded the following.

In FCM, it seems the Canonical IDs are no longer used (or at the very least extremely rarely) because of the way the Instance ID service works. To put it simply, the service works that there would only be one valid token per App Instance.

If the older token expires (for whichever reason), FCM triggers a tokenRefresh event where you would get a new registration token, and where you must also handle it accordingly (in onTokenRefresh()).


Short answer, Yes. It's still necessary.

The onTokenRefresh() method is expected to trigger whenever the token is actually refreshed. From there, it's the developer's responsibility to send the registration token towards an App Server.

BUT in an event where you weren't able to get a hold of the new registration token (e.g. forgot to save it, deleted it and only have the previous registration token, etc.), it may result to you (the developer) to send towards a supposed to be no longer valid registration token. That's when Canonical IDs come in.

I guess you can treat Canonical IDs as another safety measure so that developers can still get a hold of the valid registration token. Details about Canonical IDs (how it is handled and stuff) are mentioned in the FCM docs here.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • Firebase Admin SDK for JAVA has no way to get canonical ids. ref: https://firebase.google.com/docs/cloud-messaging/send-message , What to do in this case? – binaryKarmic Jan 07 '20 at 14:40
  • @binaryKarmic - like I mentioned in the answer update, it should no longer even be needed. If for some reason you're ending up in a place where you need to track it, then that itself is an issue. I suggest reaching out to Firebase Support. – AL. Jan 08 '20 at 08:15