Warm tip: This article is reproduced from stackoverflow.com, please click
android firebase firebase-authentication firebase-cloud-messaging firebase-admin

How to get Firebase user id from FCM token? (in admin code on server)

发布于 2020-03-30 21:16:16

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.

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?

Questioner
user2297550
Viewed
71
Frank van Puffelen 2019-02-24 23:45

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

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

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.

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.

Also see: