简体   繁体   English

在FCM(Firebase云消息传递)中,在通知中包含令牌是否安全?

[英]In FCM (Firebase cloud messaging), is it safe to include token in the notification?

When sending push notification to an Android device using FCM, is it safe to include token in the notification body? 使用FCM向Android设备发送推送通知时,在通知正文中包含令牌是否安全? Will this somehow violate security/privacy or GDPR? 这会以某种方式违反安全/隐私或GDPR吗?

In the firebase documentation ( https://firebase.google.com/docs/cloud-messaging/concept-options ), their example includes notification token in the notification: 在Firebase文档( https://firebase.google.com/docs/cloud-messaging/concept-options )中,其示例在通知中包含通知令牌:

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

Instead can we do something like this? 相反,我们可以做这样的事情吗?

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

If there is nothing wrong with including token in the notification, I was hoping I could include the token in the notification for client side check to filter receiving notification from expired token (token isn't always invalidated right away. At least in GCM it isn't) 如果在通知中包含令牌没有任何问题,我希望可以在通知中包含令牌以供客户端检查以过滤来自过期令牌的接收通知(令牌并不总是立即失效。至少在GCM中不是“t)的

NOTE: The reason I'm doing this is because when user uninstalls and reinstalls the app, the old token can still be active. 注意:之所以这样做,是因为当用户卸载并重新安装该应用程序时,旧令牌仍可以处于活动状态。 Until Firebase's cron job goes and deletes old token, the old token can still be used. 在Firebase的cron作业消失并删除旧令牌之前,仍可以使用旧令牌。 This is a problem if you have a separate server maintaining tokens. 如果您有单独的服务器维护令牌,这将是一个问题。 So I was hoping I could just include token in the notification to filter invalid notifications and invalidate old token on our private server. 因此,我希望可以在通知中包括令牌,以过滤无效的通知并使我们的私有服务器上的旧令牌无效。

In the example the token is being sent in the message, not in the notification. 在示例中,令牌是在消息中发送的,而不是在通知中发送的。 The notification is also part of the message. 通知也是消息的一部分。

The message is sent to the FCM server where, using the token, it will know to whom direct the notification. 消息被发送到FCM服务器,在该服务器上,使用令牌,它将知道将通知定向给谁。

About including the token in the notification, I would not do that. 关于在通知中包含令牌,我不会这样做。

Besides, the mobile device already has the token that has been sent to it when the device registered with FCM. 此外,当移动设备在FCM中注册时,它已经具有发送给它的令牌。 And if the device hasn't registered for any reason, like an uninstall, then even if you add the token to the notification, it will not reach the device. 而且,如果设备由于某种原因未注册,例如卸载,那么即使您将令牌添加到通知中,它也不会到达设备。

EDIT I 编辑我

You won't be able to add a token in the notification that way (as an additional attribute). 您将无法以这种方式在通知中添加令牌(作为附加属性)。 See how the json message has to be formed in the fcm docs. 了解如何在fcm文档中形成json消息。 If there is a place you could set it (which I don't recommend doing) is as part of the data . 如果有地方可以设置(我不建议这样做)作为data一部分。

The reason not to include it is that there is no reason to do so: 不包含它的原因是没有理由这样做:

The Token is not managed by your app, it is managed by the FCM server. 令牌不受您的应用程序管理,而是由FCM服务器管理。 You just need to take care of updating your server when the Token changes, in which case, the FCM api lets your app know by triggering a callback in the app ( onTokenRefresh() ). 您只需要在令牌更改时注意更新服务器,在这种情况下,FCM api通过触发应用程序中的回调( onTokenRefresh() )来通知您的应用程序。 When you do this, you keep a copy of the token in shared preferences. 执行此操作时,您将在共享首选项中保留令牌的副本。

Following last point, the app already has the token. 在最后一点之后,该应用程序已经具有令牌。 Sending it in each notification, if it gets to the mobile device, it is because it is still valid, so you already have it in shared preferences. 在每个通知中发送它(如果到达了移动设备),是因为它仍然有效,因此您已经拥有共享首选项。 On the other hand, if the token is invalid, then the message won't be received, and the app will never be aware about this. 另一方面,如果令牌无效,则将不会接收到消息,并且应用程序将永远不会意识到这一点。 Things will come back to normal when the FCM server provides a new Token to the app. 当FCM服务器向应用程序提供新令牌时,一切将恢复正常。 In which case the app is notified with a callback, and your app replaces the token in shared preferences and updates your server. 在这种情况下,应用会收到回调通知,并且您的应用会替换共享首选项中的令牌并更新您的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 云消息传递:FCM 令牌到期 - Firebase Cloud Messaging : Expiration of FCM token Android Firebase 云消息传递令牌 (FCM) 令牌太短/不完整 - Android Firebase Cloud Messaging Token (FCM) token is too short/incomplete Firebase云消息传递:无令牌和奇怪的通知行为 - Firebase Cloud Messaging: No Token and strange notification behavior 使用 Asp.Net 的 FCM(Firebase 云消息传递)推送通知 - FCM (Firebase Cloud Messaging) Push Notification with Asp.Net 如何使用FCM(Firebase云消息传递)发出紧凑的通知? - How to make a compact notification with FCM (Firebase Cloud Messaging)? 在 Kotlin 客户端应用程序中发送 FCM 推送通知 - Firebase 云消息传递 - Sending FCM Push Notification in Kotlin Client App - Firebase Cloud Messaging Firebase Cloud Messaging(FCM)注册令牌服务器端验证 - Firebase Cloud Messaging (FCM) registration token server-side validation 是一个设备还是一个帐户的FCM(firebase云消息传递)令牌? - Is FCM (firebase cloud messaging) Token for one device or for one account? 如何向FCM(Firebase云消息传递)令牌的特定用户发送消息? - How to send a message to a specific user of an FCM (Firebase Cloud Messaging) token? Android,FireBase 云消息传递,(FCM) - Android, FireBase Cloud Messaging, (FCM)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM