0

I am able to send push notification using Firebase Console.

But I want to send notification from my app (which is the admin app) without using any backend services .
I figured that I can send it using HTTP POST Rquest ,but I have to save the Authorization key in the device.
Please help me if there is any way around ? I am unable to find relevant documentation.
Thanks.

Saket Mayank
  • 55
  • 1
  • 16
  • Sending a message *to* a device requires that you specify the so-called FCM server key for authorization. As its name implies, this key should only be used in trusted environments such as a server you control. The reason for this is that having the key allows you to send messages to all users of your app. To send messages securely without setting up you own server, consider using Cloud Functions. For more on this, see https://stackoverflow.com/a/37634914 and my blog post here: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html – Frank van Puffelen Apr 06 '18 at 13:46

1 Answers1

0

As you are talking about HTTP POST I assume you are talking about remote notification.

You cannot send a push notification without the token which has to be saved if the user grants the permission.

Just for the sake of the example here's what it a HTTP POST request looks like in nodejs in order to send the notification.

const request = require("request");

const options = { 
  method: 'POST',
  url: 'https://fcm.googleapis.com/fcm/send',
  headers: 
   {
     Authorization: 'key=HERE_GOES_YOUR_KEY' },
  body: 
  { 
     to: 'HERE_GOES_YOUR_TOKEN',
     notification: { title: 'hello', body: 'world' }
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
Sid
  • 14,176
  • 7
  • 40
  • 48
  • Thanks for the reply . I am aware of the information you provided . I want to know does Firebase provides any method to send notification . – Saket Mayank Apr 06 '18 at 13:30
  • I just explained that, you have to use the `token` for remote push notification, there's no other way. @SaketMayank – Sid Apr 06 '18 at 14:16