Messaging using Firebase do not behave like Firebase console - firebase

I can succesfully send a post request from my server at home to the Firebase server. The message is delivered to the client without a problem.
Except that the app must be either running or in the background.
If the app is closed the message goes to limbo. There is nothing in the system tray, there is no sound, nothing.
Is this the expected behavior?
This is the curl command I am using:
curl -X POST --header "Authorization: key=AIzaSyBntseBqux9nBX8y" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"fxhL9uQBYUo:APA91bGaEWqTJ2mde1vSlfOZWHYrYTQLbZdFih2hs_wszaxPsthfMN5lnxH6RHquUImmT\",\"data\":{\"action\":\"run\"}}"
Am I missing some extra fields that make the device act like it is doing now?
PS: Server Key and Token are not real.

Your code is sending a data message, the Firebase Notifications console sends notifications messages.
One big difference between these two types of messages is that notification messages are automatically shown in the system notification area if your app is not in the foreground.
See this page in the Firebase documentation explaining the difference between these message types.

Related

OAUTH token for firebase cloud storage?

I am trying to upload an image to my cloud storage on firebase on an application where I won't have access to googles client libraries. From my understanding, I've followed this documentation on uploading images:
curl -X POST --data-binary #OBJECT_LOCATION
-H "Authorization: Bearer OAUTH2_TOKEN"
-H "Content-Type: OBJECT_CONTENT_TYPE"
"https://storage.googleapis.com/upload/storage/v1/b/BUCKET_NAME/o?uploadType=media&name=OBJECT_NAME"
Specifically, on postman I added the file location, the OAUTH_TOKEN I believe I used was from this location:
enter image description here
However, I've run into an unauthorization error, but I did change my rules on firebase cloud to allow anyone to read/write just for testing. However just to clarify, I can use the bucketname on my cloud storage as well correct? I guess the problem must lie in not having the right OAUTH token which I am still confused on how to generate. any help is greatly appreciated.

How can i secure my Firebase "subscribe to topic" from the web client?

In firebase FCM i can subscribe to a topic through the web client like this:
curl -X POST -H "Authorization: key=<your_server_key>" -H "Content-Type: application/json" -H "Content-Length: 0" "https://iid.googleapis.com/iid/v1/<your_instance_token>/rel/topics/<topic_name>"
The only usage i have form Firebase is sending push notifications form the server to web clients that are subscribed to a specific topic.
But how can i prevent unwanted people from subscribing to my topics?
FCM topics are not "secure". Anyone can subscribe to them. You should not distribute sensitive data over a topic.
If you want to send sensitive data to only certain users, you should be using device tokens to send messages directly. Either that, or accept the fact that any client can "listen in" on the topic, if they just know the name of the topic and the configuration of your project (which is essentially public since it gets baked in your app at build time).

How to efficiently send personalized notification to 10k users using FCM

FCM gives two options to send notifications:
[to] - takes one gcm token
[registration_ids] - takes array of 1000 gcm token
So, If I had to send message to 10k users then using registration_ids it will take 10 request to fcm server. But the message is same for every request. I can change message every time in case of to but then i will have to send 10k different requests.
Now, I want to send personalized message.
eg: registration_ids[0]='ggggss' his name is alpha. I would want to send hey alpha,.... similarly for every user.
Is there a way to send personalized notification efficiently?
example syntax: curl -X POST --header "Authorization: key=" \
--Header "Content-Type: application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"to\":\"\",\"notification\":{\"body\":\"Yellow\"},\"priority\":10}"
There is no built-in mail merge functionality in Firebase Cloud Message (as far as I know). You will either have to send the same message to multiple users, or perform a separate API call for each user

Getting invalid token in Firebase Cloud Messaging in cURL command and postman

guys, I'm trying to get information about app instance and I'm also trying to subscribe an app instance to a Google Cloud Messaging topic but the problem is whenever I try to use the server key it throws me the error of invalid token and when I try to use the web api key it gives me unauthorized
I've tried it using postman but the results are the same. Can somebody tell me what is it that I'm doing wrong
Here is the screenshot of the request that I'm sending using postman
and here is the screenshot of the request that I'm sending using curl

Ionic 2 Firebase Cloud Messaging Notifications - Xcode says Connected to FCM, but message never comes through

I've gotten my Ionic 2 app configured, Firebase Cloud Messaging, configured, and when I install my Ionic app onto my phone, I don't get any errors. In fact, my log says Connected to FCM.
The problem is that when I log into my Firebase console and navigate to Notifications -> New message, I create a "New Message" with the target set as "User Segment" with my iOS app selected. and when I click "Send Message", my device never receives the app even when I've got the app running. And my log doesn't say anything beyond the "Connected to FCM" like it did when I installed the app.
Does anyone have any idea what might be going on here?
Thanks in advance!
I realized there was a whole step I was forgetting to get setup with Firebase but after going through the documentation here, I was able to send notifications: https://firebase.google.com/docs/cloud-messaging/ios/certs
There a lot of potential firebase messaging errors and the console doesn't give any return info. Testing with a curl is a lot better:
curl -X POST -H "Authorization: key=<your key from the firebase console> -H "Content-Type: application/json" -d '{
"notification": {
"title": "Yo friend says",
"body": "Pay attention to me",
},
"to": <firebase instance id>
}' "https://fcm.googleapis.com/fcm/send"

Resources