How to check FCM registration token on server?

I received my Firebase Cloud Messaging registration token for web push. And I sent this to my server to save to the database for later click. But how can I verify that this token is valid or fake?

I tried this one , but I think this is for Auth tokens not for web push.

Someone may send a random fake token request to my server. I want to prevent this before saving to db.

Edit: he decided, and I wrote a simple class to quickly use FCM for web promotion. https://github.com/emretekince/fcm-web-push

+3
source share
2 answers

When sending to an invalid registration token, you should get 200 + error: InvalidRegistration :

Check the format of the registration token that you pass to the server. Make sure it matches the registration token that the client application receives from registration through Firebase notifications. Do not truncate or add additional characters.

This is the answer when you try to send a simple cURL request where the registration token is simply arbitrarily made:

curl --header "Authorization: key=$[your_server_key_here]" \
       --header Content-Type:"application/json" \
       https://fcm.googleapis.com/fcm/send \
       -d "{\"registration_ids\":[\"ABC\"]}"

Note what I added in "ABC"the parameter registration_ids. If this is a valid registration token, but it is not related to your project, you will probably get 200 + error: NotRegistered .

, , dry_run

, true, .

+4

- dry_run= true, AL. .

- API- InstanceId:
https://developers.google.com/instance-id/reference/server

+2

Source: https://habr.com/ru/post/1016640/


All Articles