我获得了用于网络推送的 Firebase 云消息传递注册 token 。 我将其发送到我的服务器以保存在数据库中以供以后推送。 但是我如何验证这个 token 是有效的还是假的?
我试过了this但我认为这是针对 Auth token 的,而不是针对网络推送的。
其他人可以向我的服务器发送随机伪造 token 的请求。我想在保存到数据库之前阻止这种情况。
编辑:它已经解决了,我写了一个简单的类来快速使用 FCM 进行网络推送。 https://github.com/emretekince/fcm-web-push
最佳答案
当发送到一个无效注册 token 时,您应该收到 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.
这是当您尝试发送一个简单的 cURL 请求时的响应,其中注册 token 是随机生成的:
curl --header "Authorization: key=$[your_server_key_here]" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
请注意,我在 registration_ids
参数中添加了 "ABC"
。如果它是一个有效的注册 token ,但与您的项目无关,您可能会收到 200 + error:NotRegistered .
您可以尝试使用 dry_run 从服务器发送测试消息以查看响应,而无需向设备发送实际消息。参数:
This parameter, when set to true, allows developers to test a request without actually sending a message.
关于node.js - 如何验证服务器上的 FCM 注册 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41552610/