How to use an existing GCM token in another Firebase project?

Suppose I have a Google Cloud Project (GCP1) with GCM enabled with client ID P1.

Now I created a standalone Firebase F2 project without importing it into GCP1. I also released F2 for production. (Alternatively, I imported F2 from an existing firebase.com project into a new Firebase console).

I use a server server to send push notifications. When I send a push to GCM token generated via GCP1 from project F2, it fails (naturally) due to an invalid client identifier. Are there working conditions for using the GCM tokens generated for P1 inside F2?

+5
source share
1 answer

When sending messages from your internal server, you need to authenticate the request using the API key associated with the project (sender identifier) ​​used to generate the GCM / FCM token.
Due to security restrictions, there is no workaround.

For existing GCM users, the best migration is to import an old project into the Firebase Console. This will allow you to target both the old and the new client, since sender-id will not change. Steps here: https://developers.google.com/cloud-messaging/android/android-migrate-fcm

If this is not an option (you have already created a new project Firebase, different from the previous Google Cloud Project), you have two options:

  • A simple and recommended approach: change your background code to keep which client launched the gcm / fcm token. Then use the correct API key when sending messages from your server. (The API key associated with the old project for old clients, and the new API key for new clients who use the new Firebase project).

  • If you can’t change your server at all: in FCM, you can create an additional token for the old SenderID using the API:
    FirebaseInstanceId.getInstance().getToken("old-sender-id", "FCM")
    Since this token is associated with the old-sender identifier, your back-end will be able to send messages to it using the old project's API key.
    Note. this does not affect the Firebase console based on the new sender ID.
    This console will only be able to target new customers, which include firebase sdk and the corresponding google_services.json file.

+8
source

All Articles