如何从FCM令牌获取Firebase用户ID? (在服务器上的管理代码中) [英] How to get Firebase user id from FCM token? (in admin code on server)

查看:173
本文介绍了如何从FCM令牌获取Firebase用户ID? (在服务器上的管理代码中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我登录的Android客户端在我的服务器上注册其令牌.问题是我不确定特定客户端发送的令牌是否真正属于该客户端用户ID.错误的客户端可能会注册其他用户的有效令牌.

My signed-in Android clients register their tokens with my server. The problem is I am not sure whether the token sent by a particular client genuinely belongs to that client user id. A bad client could register valid tokens of other users.

给出一个FCM令牌和一个用户ID,我在服务器上的管理代码如何验证该令牌确实属于(经过身份验证的)用户ID?

Given an FCM token and a user id, how can my admin code on the server verify that the token indeed belongs to the (authenticated) user id?

推荐答案

在Firebase级别上,身份验证UID和云消息传递实例ID令牌之间没有连接.

On a Firebase level there is no connection between a Authentication UID, and a Cloud Messaging Instance ID token.

Firebase身份验证UID唯一标识一个用户.如果该用户在其他设备上登录,则他们具有相同的UID值.

A Firebase Authentication UID uniquely identifies a user. If that user signs in on a different device, they have the same UID value.

Firebase身份验证实例ID令牌标识单个设备上的单个应用程序.如果其他用户登录该应用,则该应用将保留相同的实例ID令牌.

A Firebase Authentication Instance ID token identifies a single app on a single device. If a different user signs in to that app, the app will keep the same Instance ID token.

如果要将UID与FCM令牌相关联,则必须在应用程序代码中执行此操作.例如,当用户退出其应用程序时,许多开发人员会清除FCM实例ID令牌.这样可以确保在同一设备上登录的新用户将获得新的实例ID令牌.

If you want to associate a UID with an FCM tokens, you have to do that in your application code. For example, many developers clear the FCM Instance ID tokens when the user signs out of their app. This ensures that a new user who signs in on the same device will get a new Instance ID token.

另请参阅:

  • Firebase Cloud Messaging Auth Tokens vs Registration Token
  • What is the proper way to capture device registration tokens in order to send notifications via Firebase Cloud Messages?

这篇关于如何从FCM令牌获取Firebase用户ID? (在服务器上的管理代码中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆