9

I am the new for FCM. Here are some questions about the registration token:

  1. Is the registration token generated by the FCM connection server?
  2. Does the token change periodically in the connection server?
    • When?
    • Will it force the onTokenRefresh() in the app to be called?

I have googled for a week but didn't get any details. Please help. Thanks.

AL.
  • 36,815
  • 10
  • 142
  • 281
eldon
  • 91
  • 1
  • 1
  • 2

1 Answers1

17

1. Is the registration token generated by the FCM connection server?

No. It gets generated by the FirebaseInstanceID. The way I understand the flow of event on first time registration:

  1. The app retrieves a unique Instance ID.
  2. The registration token is generated by calling the InstanceId.getToken().
  3. Developer (usually) sends the token to the App Server.

2. Does the token change periodically in the connection server?

I think the onTokenRefresh() docs pretty much answers this.

Called when the system determines that the tokens need to be refreshed. The application should call getToken() and send the tokens to all application servers.

This will not be called very frequently, it is needed for key rotation and to handle Instance ID changes due to:

  • App deletes Instance ID
  • App is restored on a new device
  • User uninstalls/reinstall the app
  • User clears app data

The system will throttle the refresh event across all devices to avoid overloading application servers with token updates.

See this part of the docs for more details.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • 1
    Thanks for your reply. The registration flow is different from GCM. For GCM, the registration id is returned from the Cloud. But it is generated by SDK for FCM. Right? And may i know when the key rotation will be triggered? (caused by token expired?) – eldon Dec 12 '16 at 03:15
  • @eldon FCM has GCM *under the hood*, so the registration flow is not different at all. The *key rotation* you mentioned is probably *when* will a registration token get refreshed, which is already mentioned above. You should just handle `onTokenRefresh` accordingly (sending the new token to your App Server every time it is refreshed) and it should be fine. – AL. Dec 12 '16 at 03:25
  • May i know if i clone phone A to phone B using Titanium Backup app, will they have the same registration token? And does the notification send to phone A can be reached to phone B as well? – eldon Dec 12 '16 at 03:38
  • @eldon I'm not familiar with Titanium Backup App so I'm unable to provide an answer. But normally, each registration token should be unique, and is somehow tied to the device id. See this [answer](http://stackoverflow.com/a/11587181/4625829) by Trevor Johns. – AL. Dec 12 '16 at 03:41
  • Can anyone help me understaanding what does the "App is restored on a new device" scenario really means? Would a OS update trigger it ? – Luiz Henrique Martins Lins Rol Jul 11 '18 at 12:25
  • can we get token id without registering app in firebase console – anju jo Jan 16 '19 at 09:45