Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase (FCM) registration token

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.

like image 901
eldon Avatar asked Dec 12 '16 01:12

eldon


People also ask

What is registration token in FCM?

On initial startup of your app, the FCM SDK generates a registration token for the client app instance. This is the token that you must include in targeted send requests from the API, or add to topic subscriptions for targeting topics.

Why FCM token is used?

Firebase Cloud Messaging (FCM) is a messaging solution that lets you reliably send messages at no cost to both Android & iOS devices. Using FCM, you can send data payloads (via a message) to a device for a specific application. Each message can transfer a payload of up to 4KB to a client.

How can I get token from Firebase?

Firebase gives you complete control over authentication by allowing you to authenticate users or devices using secure JSON Web Tokens (JWTs). You generate these tokens on your server, pass them back to a client device, and then use them to authenticate via the signInWithCustomToken() method.


1 Answers

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.

like image 70
AL. Avatar answered Sep 28 '22 07:09

AL.