How to authenticate FCM (Firebase Cloud Messaging)?
After 3 days of searching, I found a solution in the documentation:
https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth
Validate Firebase Registration Tokens
There is currently no way to validate tokens on your own.
I presume that you intend to validate it by checking the format, which would be unadvisable. Token formats have the tendency to change as Google wants it too.
How to verify FCM registration token on server?
When sending to an invalid registration token, you'll should receive 200 + error:InvalidRegistration:
Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with Firebase Notifications. Do not truncate or add additional characters.
This is the response when you try to send a simple cURL request where the registration token is just randomly made:
curl --header "Authorization: key=$[your_server_key_here]" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
Notice that I added in "ABC"
, in the registration_ids
parameter. If ever it is a valid registration token, but is not associated to your project, you'll probably receive 200 + error:NotRegistered.
You can try sending a test message from your server to see the response without sending an actual message towards the device by using the dry_run parameter:
This parameter, when set to true, allows developers to test a request without actually sending a message.
Verify if fcm token belongs to an android or ios device
The following might help you to customize notification messages based on the platform:
https://firebase.google.com/docs/cloud-messaging/send-message#customize-messages-across-platforms
If you want to distinguish the tokens manually, then a possible hack would be to add the platform name as a prefix when storing tokens in a database from your frontend app. Then, you can filter out the tokens on your backend by implementing a programming logic i.e. creating separate arrays for android and IOS tokens.
I don't think there is a way to just see the token and tell from which platform it belongs.
Related Topics
Android Sdk: Get Raw Preview Camera Image Without Displaying It
Change Viewpager Animation Duration When Sliding Programmatically
How to Change the Toolbar Text Size
Difference Between Extending Lifecycleactivity,Activity,Actionbaractivity & Appcompactactivity
How to Keep Android Applications Always Be Logged in State
How to Add a Button to a Preferencescreen
How to Show Snackbar at Top of the Screen
Encoding H.264 from Camera with Android Mediacodec
How to Compile C into an Executable Binary File and Run It in Android from Android Shell
Retrofit Uploading Multiple Images to a Single Key
Alarmmanager Android Every Day
Android: Create Circular Image with Picasso
Login Error: There Is an Error in Logging You into This Application. Please Try Again Later
When Exactly Are Onsaveinstancestate() and Onrestoreinstancestate() Called