MatthieuLemoine / push-receiver

A library to subscribe to GCM/FCM and receive notifications within a node process.
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
199 stars 75 forks source link

An API this library relies on will be turned off June 20, 2024 #68

Open RandomEngy opened 11 months ago

RandomEngy commented 11 months ago

This library calls https://fcm.googleapis.com/fcm/connect/subscribe for the final FCM subscription step, which I confirmed with the Firebase team to be slated for removal on June 20, 2024. This is not in the explicit list of URLs affected but is considered part of the "Legacy Web SDK".

KillTrot commented 11 months ago

Do you have any official ressource for that, where I can find more information and needed changes?

RandomEngy commented 11 months ago

I linked to the official resource...

developerfromjokela commented 10 months ago

Hmm, that's troubling. Did firebase team advise to which API endpoint we should change to keep it running? @RandomEngy

RandomEngy commented 10 months ago

They did not. They referenced this guide to setting up FCM on a web app. I think the best bet right now is adapting from the firebase-js-sdk source code.

Per our engineers, the endpoint https://fcm.googleapis.com/fcm/connect/subscribe is included in the list of APIs that will be deprecated. It's part of Legacy Web SDK, although users may call it directly before. For now, I think you'll need to use FCM Web SDKs for obtaining FCM registration tokens.

I've also filed a request to include the endpoint in our FAQ page to avoid confusion moving forward. Let me know if there's anything else I could help you with.

saenzramiro commented 6 months ago

Any updates on this?

RandomEngy commented 6 months ago

I took a stab at this today and decided I'm going to give up and use Amazon SNS for my desktop apps instead of trying to get FCM working. It has actual support for running in NodeJS and Rust. Fixing this library would mean implementing the web push protocol from scratch.

alchemicas commented 6 months ago

Hello! Given that this library seems to not be supported by the author anymore, it's using soon-to-be deprecated APIs and has various bugs accumulated over time, I decided to write my own version.

It does everything that push-receiver already does and a little bit more. For the people who are going to migrate to my library, there is also a function exposed for retro-compatibility that subscribes to FCM using the sender ID.

Documentation: Aracna FCM Docs Source: Aracna FCM Source

RandomEngy commented 6 months ago

Oh heck yes. I was looking more into SNS and it's not really a good replacement for proper push. I think I may actually be able to save push notifications in Rust/Tauri and update fcm-push-listener by following this library.

saenzramiro commented 6 months ago

@Alchemicas Sounds interesting! Thank you for sharing your library. Does it support Electron?

developerfromjokela commented 6 months ago

@Alchemicas is there a possibility to not use FCM credentials like in this library? Or has the methodology changed in new API?

alchemicas commented 6 months ago

@Alchemicas Sounds interesting! Thank you for sharing your library. Does it support Electron?

Hi @saenzramiro , yes it does work with Electron, only on the main process of course.

@Alchemicas is there a possibility to not use FCM credentials like in this library? Or has the methodology changed in new API?

Hi @developerfromjokela , I can't give a 100% accurate answer because we're always talking about APIs that are not documented anywhere by Google, everything that is inside these libraries is an effort of reverse engineering. Having said this, the way the latest Firebase js sdk does things is with a new registration endpoint that requires an auth token generated with Firebase API Key, App ID and Project ID.

Maybe, and I say maybe, we could find an alternative way by reverse engineering the API calls made by native apps using FCM, but the way the web sdk does things is what's currently in my library.

If you're worried about exposing your Firebase api key, I'm pretty sure it's safe to have out in the open 👍

developerfromjokela commented 6 months ago

@Alchemicas can I use sender ID argument? I have a third party service I want to receive push notifs from, with push-receiver i just put it there and it worked. In arcana i coudln't quite figure out.

alchemicas commented 6 months ago

@Alchemicas can I use sender ID argument? I have a third party service I want to receive push notifs from, with push-receiver i just put it there and it worked. In arcana i coudln't quite figure out.

You can @developerfromjokela , just use the subscribeToFCM function. But by June you'll have to figure out a way to leverage the new APIs and generate tokens through registerToFCM.

If you already have a sender id you should also be able to get the firebase config somehow if you do have access to the firebase console.

developerfromjokela commented 6 months ago

@Alchemicas can I use sender ID argument? I have a third party service I want to receive push notifs from, with push-receiver i just put it there and it worked. In arcana i coudln't quite figure out.

You can @developerfromjokela , just use the subscribeToFCM function. But by June you'll have to figure out a way to leverage the new APIs and generate tokens through registerToFCM.

If you already have a sender id you should also be able to get the firebase config somehow if you do have access to the firebase console.

I just tried with both registerToFCM and subscribeToFCM and none of them receive notifications. But using push-receiver notifications get delivered.

pedroGitt commented 6 months ago

It does everything that push-receiver already does and a little bit more. For the people who are going to migrate to my library, there is also a function exposed for retro-compatibility that subscribes to FCM using the sender ID.

Documentation: Aracna FCM Docs Source: Aracna FCM Source @Alchemicas

alchemicas commented 6 months ago

I just tried with both registerToFCM and subscribeToFCM and none of them receive notifications. But using push-receiver notifications get delivered.

Uhm, I can't help you further without seeing how you're implementing it. I'll try to publish an example this week on the repo to avoid any confusion.

  • I just went through your documentation.. what is exactly the YOUR_VAPID_KEY ? The public key we generate from the "Cloud messaging" tab in the "Web Push certificates" section?
  • One could have expected a symmetrical use of ./google-service-account.json file from sendFcmMessage() in registerToFCM(),
  • I'm going to try your lib.. nice job!
ychumpov commented 6 months ago

@Alchemicas Does you use https://fcm.googleapis.com/fcm/connect/subscribe for your fcm registration?

alchemicas commented 6 months ago

@Alchemicas Does you use https://fcm.googleapis.com/fcm/connect/subscribe for your fcm registration?

Hi @ychumpov , only if you use the deprecated subscribeToFCM function, otherwise you can use the new APIs with registerToFCM, it's all written in the docs

developerfromjokela commented 6 months ago

@Alchemicas Does you use https://fcm.googleapis.com/fcm/connect/subscribe for your fcm registration?

Hi @ychumpov , only if you use the deprecated subscribeToFCM function, otherwise you can use the new APIs with registerToFCM, it's all written in the docs

If you could do a implementation like in https://github.com/BRUHItsABunny/go-android-firebase, so that I can just copy info from this mobile app and insert it there. Basixally you use different firebaseinstallations request body.

miafoo commented 4 months ago

I've just published this package: https://github.com/miafoo/fcm-web-push - it's based on this library + the rust implementation by @RandomEngy above. It's using the new APIs, is quite minimal and has very few dependencies. I've only tested it on a private electron project and it seems to work quite well there so far.

ychumpov commented 4 months ago

@Alchemicas I noticed that in "old" implementation the appId was generated each time with new value: // Should be unique by app - One GCM registration/token by app/appId string appId = "wp:receiver.push.com#" + some kind of guid

Is it also the same in your lib?

alchemicas commented 4 months ago

@Alchemicas I noticed that in "old" implementation the appId was generated each time with new value: // Should be unique by app - One GCM registration/token by app/appId string appId = "wp:receiver.push.com#" + some kind of guid

Is it also the same in your lib?

The app_id randomness is up to the integrator of @aracna/fcm

choiman1559 commented 3 months ago

Guys, I just completed to write FCM receive library exclusive for electron @cuj1559/electron-push-receiver

It was originally built based on this FCM library for electron, so it can be used almost as is, except that you need to add an API key.

If you're interested, Please check it out.

javajuice1337 commented 3 months ago

I too was dreading the Google API removal for FCM subscribing so I tried the @aracna/fcm library, but the receiver would error when reading the notification.

I ended up porting the FCM registration from it into a fork of push-receiver here: https://github.com/javajuice1337/push-receiver-v2

Happy coding! 😃

piyushgarg commented 3 months ago

Has anyone able to get the notification from third party sender using the new fcm registration? As @developerfromjokela also checked, its not working. In the old api there is a way to authorize the sender but in the newer API's there is no such as senderId.

async function registerFCM({ senderId, token }) {
...
 form : {
      authorized_entity : senderId,
....
developerfromjokela commented 3 months ago

Has anyone able to get the notification from third party sender using the new fcm registration? As @developerfromjokela also checked, its not working.

In the old api there is a way to authorize the sender but in the newer API's there is no such as senderId.


async function registerFCM({ senderId, token }) {

...

 form : {

      authorized_entity : senderId,

....

With old API i just set sender ID and it just worked fine with my usecase. On newer one it doesn't.

amilich commented 1 month ago

-v2

I'm seeing unauthorized errors or invalid authorization credentials. Does this library support the new FCM authorization changes?