jeudi 21 février 2019

Firebase FCM — portability to plain Web Push protocol?

I would like to build push notifications on top of [Firebase Cloud Messaging][1, to benefit from sending to multiple subscribers at the same time. This implies a Google account and a Firebase project to be created.

But I would like the ability to convert the platform to usage of plain Push API. The difference is that the later does not require a Google account, but it does require authentication with the push service by signing requests with VAPID keys.

The browser gives you a subscription like this:

{
  "endpoint":"https://fcm.googleapis.com/fcm/send/duhACWCPtgQ:APA91bHJcNGYk8OTjbdcy-YWVkZUtMB9ztwzFlj54KfKGi46wIb9j9z3Gwop3j534rVsNALG3ccXRz-O8uLJZDfosAK4wSh3Jwr6KlMiaipBnglcLb4Z8r3Lc9kMzgrS1KC9jGpPHsn_",
  "expirationTime":null,
  "keys":{
    "p256dh":"BLeAlKXQUMJjX-jeERPg1Jw50g2ro7zxemsjxX9YsgQ6XhKyAlu0v7pOPzcmwh6zyfYRcHCnI3VFzO12e-UNUzE",
    "auth":"7o_bNZw4l-6sg85Yt95zqA"
  }
}

Theoretically I could save this on the server side and use it to push messages without involving a Firebase account.

But unfortunately it doesn't work because I need a VAPID key pair for singing the messages. I tried using messaging. as described in their docs and no luck:

messaging.usePublicVapidKey("BKagOny0KF_2pCJQ3m....moL0ewzQ8rZu");

Basically the only way I am able to send push notifications to this subscriber is if I use the Firebase Admin SDK, doing authentication with the Firebase account and using their notion of a token that identifies the user, but that's not what I want.

Any solutions available for switching off Google's FCM while preserving the subscribers?




Aucun commentaire:

Enregistrer un commentaire