My website uses GCM (via OneSignal)
push notifications system.
I have to migrate push notification system to FCM (Firebase).
My goal is to migrate old tokens (and theirs relative tags/preferences) stored onto OneSignal into mine DB (on MongoDB) and send to that tokens my push notification via Firebase.
Reading Firebase's doc I don't understand if it is possible and how it is possible to reuse (or migrate/translate) old OneSignal tokens with Firebase.
Then:
Is it possible to reuse old OneSignal token with Firebase?
If n°1 is FALSE, how can I migrate old token to new token accessible with Firebase? Is there an API or JS method defined into Firebase SDK in order to translate old tokens.
I'm not familiar with how OneSignal works with GCM/FCM. What you should do is verify if the token used for OneSignal is either different or same to the actual registration token GCM works on.
The usual token format for GCM/FCM is something like this: 123456abcd:123456789abcdefghij. For a list of known characters for a GCM/FCM registration token, see here.
If it is the same, then you could simply use them as they are while proceeding to use FCM. Since FCM is still compatible with GCM tokens. However, there seems to be a really old version of GCM tokens that may be considered different from the latest format of GCM/FCM tokens (see here).
If the token is different, then unfortunately, I don't think there is a way for you to import those tokens to FCM (similar post, but for parse.com tokens). You could ask the OneSignal team if they might have the corresponding GCM tokens, but I can't say for sure.
Disclaimer: I'm no way associated or representing OneSignal in any manner.
Related
I want send notifications to mobile app. For that I need JWT tokens.
In all Google's documentation says that I should use Admin SDK for obtaion tokens, but i can't do it.
How to obtain access and refresh tokens without Google's libraries?
I need URL, HTTP method and request payload.
After 3 days of searching, I found a solution in the documentation:
https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth
I would like automate setting the APNs Authentication Key for push notifications, as well as the Team ID for an iOS App in firebase.
Therefore I would need to do this using an API (Rest, Go, Node.js, ...) Is this possible?
According to firebase support this is currently not possible. (Answer from May 2021)
For a new Firebase project I add the SenderId to my desktop websites manifest (and do not use VAPID authentication).
On a successful pushManager.subscription() the token I get back from the pushSubscription is of the format:
https://android.googleapis.com/gcm/send/*instance_token*
I expected it to be using the firebase endpoint instead:
https://fcm.googleapis.com/fcm/send/*instance_token*
I can successfully send push notifications to this token through the firebase endpoint.
My questions are:
Why do I get a GCM endpoint in the token for a firebase project?
Will this always be the case or is something going to change when GCM is discontinued?
Can we continue to use the legacy approach of the gcm_sender_id in the manifest (over VAPID)?
Our goal is sending notifications to groups of devices from our backend, and only from server side is possible to know which device should receive the notification.
We've done some attempts with AppCenter because we mostly work with Xamarin iOS/Android/Forms, but now we have the doubt that it's probably better to use directly Firebase API because wider and more powerful.
I see that with new version of API (HTTP V1) is not possible to send a notification to a list of tokens, feature that was available in legacy API using registration_ids parameter (https://firebase.google.com/docs/cloud-messaging/send-message).
Device group name (legacy protocols only)
I cannot use topics because when it's time to send the communication is a server's responsibility to prepare the "mailing list" for notifications.
I was thinking to use device group messaging (https://firebase.google.com/docs/cloud-messaging/android/device-group) but these are part of the legacy api, and I'm not sure if it makes sense/it's possible to use them with new version of API.
Is an option to send a batch of 100-200-500 push notifications each one to only one token? In theory there isn't a limit to notifications which is possible to send, but I'm worried that sending too many of them I could risk to be banned.
Is it better to use legacy API? Also AppCenter (Microsoft) uses legacy API, it's evident because of how the setup works and because from AppCenter's console it's possible to send notifications to a list of tokens, feature unavailable on Firebase's console.
Another person just asked something similar but the answer was to use topics (How to send firebase notification for all user at a time?).
Got here from the link in your comment in my answer here. And just to reiterate my response there, when sending messages to multiple tokens with v1, the suggested approach now is to use Topics Messaging, since registration_ids is not supported.
Is it better to use legacy API?
v1 was described as the more secure, cross platform, future proof way of sending messages to FCM clients. More secure since it uses OAuth2 security model.
However, if your use-case is better with using the legacy API, then I suggest you go ahead with using it.
This page suggests that you should stay with the legacy API if you want to continue to use the multicast feature: https://firebase.google.com/docs/cloud-messaging/migrate-v1
Any apps that use device group messaging or multicast messaging, however, may prefer to wait for future versions of the API. HTTP v1 does not support these features of the legacy API.
Lets say I have Google Cloud Project (GCP1) with GCM turned on with Client id P1.
Now I have created a standalone Firebase project F2 WITHOUT importing it to GCP1. I have also released F2 to production. (Alternatively, I have imported F2 from an existing firebase.com project into the new Firebase console).
I use a backend server to send push notifications. When I send a push to a GCM token generated via GCP1 from the F2 project, it fails (naturally) because of incorrect client ID. Are there work-arounds to enable use of GCM tokens generated for P1 within F2?
When sending messages from your back-end server, you need to authenticate the request with the API-KEY associated with project (sender-id) used to generate the GCM/FCM token.
Due to security restrictions here are no workaround for this.
For existing GCM users the best migration consists in importing the old project into the Firebase Console. This will allow you to target both old and new client, since the sender-id will not change
Steps here: https://developers.google.com/cloud-messaging/android/android-migrate-fcm
If that is not option (you have already created a new Firebase Project distinct from the previous Google Cloud Project) you have two possibilities:
Easier and recommended approach: change your back-end to store which client originated the gcm/fcm token. Then use the correct API-KEY when sending messages from your back-end. (the API-KEY associated to the old project for old clients, and the new API-KEY for new clients that are using the new Firebase project).
If you cannot change your back-end at all: in FCM you can create an additional token for the old SenderID, using the API:
FirebaseInstanceId.getInstance().getToken("old-sender-id", "FCM")
Because this token is associated to the old-sender-id your back-end will be able to send messages to it using the API-KEY of the old project.
Note: this doesn't affect the Firebase Console which is based on the new-sender-id.
That console will be able to target only the new clients that are including the firebase sdk and the associated google_services.json file.