Eneris / 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
16 stars 16 forks source link

Register request has failed with "Not Found" #18

Closed tsightler closed 4 months ago

tsightler commented 4 months ago

I feel like I'm just being dense here, but I just can't get this new version to work. Created a new project and have my firebaseConfig credentials, however, this doesn't even seem to be where the issue is as it fails with the GCM registration. Just using the provided example I put in my firebase credentials, but it doesn't even get to the stage of registering with FCM because the GCM registration fails:

Register request has failed with Error=PHONE_REGISTRATION_ERROR
Retry... 1
Register request has failed with <HTML>
<HEAD>
<TITLE>Not Found</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<!-- GSE Default Error -->
<H1>Not Found</H1>
<H2>Error 404</H2>
</BODY>
</HTML>

This retries 5 times and then eventually exits with this:

/home/tsightler/GitHub/ring-mqtt/node_modules/@eneris/push-receiver/dist/gcm.js:78
            throw new Error('GCM register has failed');
                  ^
Error: GCM register has failed
    at postRegister (/home/tsightler/GitHub/ring-mqtt/node_modules/@eneris/push-receiver/dist/gcm.js:78:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async doRegister (/home/tsightler/GitHub/ring-mqtt/node_modules/@eneris/push-receiver/dist/gcm.js:57:22)
    at async exports.default (/home/tsightler/GitHub/ring-mqtt/node_modules/@eneris/push-receiver/dist/gcm.js:25:25)
    at async PushReceiver.registerIfNeeded (/home/tsightler/GitHub/ring-mqtt/node_modules/@eneris/push-receiver/dist/client.js:163:21)
    at async PushReceiver.connect (/home/tsightler/GitHub/ring-mqtt/node_modules/@eneris/push-receiver/dist/client.js:103:9)
    at async file:///home/tsightler/GitHub/ring-mqtt/push-receiver.js:28:5

Looking through the code, it seems like this portion of the code is unchanged from previous versions, but I'm not sure if legacy GCM registration is working anymore, however, it's possible I'm completely off-base.

tsightler commented 4 months ago

OK, I think I figured this out, current versions require not just firebase configuration, but also requires vapidKey, which requires using generate key pair for web push certificates. Maybe this should be noted in the docs as previous versions used a default vapidKey if none was provided. Without providing a vapidKey, the GCM registration fails.

Eneris commented 4 months ago

Hi. I'am glat that you've found a way to make it work.

That seems to be a new one. I've noticed that it stopped working with the default vapidKey passed a few times without any. It seems that I'll have to make it a required parameter. Luckily for us, the vapidKey is also provided by creating a firebase project so it's just one more variably to copy.

tsightler commented 4 months ago

Well, work is probably optimistic, I'm not getting any error and it appears to be working based on debug logs, but, so far, I've been unable to successfully receive any messages.

To be clear, I can receive messages with the example, if I send a message within my own registered application, however, I need to receive push message from another 3rd-party application which I don't control, other than I can tell it the FCM token it should use to push messages. This was working perfectly with 3.x push-receiver (and still does) but, so far, I can't receive messages from it with 4.x push-receiver. Hopefully I'm still just doing something wrong, but at least it is progress.

Eneris commented 4 months ago

Any sender that you want to receive messages from should use the same vapid key. You can try to use the firebase generic vapid key which was used in the previous versions BDOU99-h67HcA6JeFXHbSNMu7e2yNNu3RzoMj8TM4W88jITfq7ZmPvIM1Iv-4_l2LxQcYwhqby2xGpWwzjfAnG4

https://github.com/firebase/firebase-js-sdk/blob/a90255a276b577e8909b6af444eede3e51dcdcf1/packages/messaging/src/util/constants.ts#L22

tsightler commented 4 months ago

It seems not possible to register with GCS when using this key. If I use my generated VAPID key, registration works, but I receive no messages from 3rd-party. I tried changing the VAPID key after registration, but that didn't seem to work either. I'm not sure what is going on, it could be some other issues in my code for sure.

Eneris commented 4 months ago

It seems not possible to register with GCS when using this key. If I use my generated VAPID key, registration works, but I receive no messages from 3rd-party. I tried changing the VAPID key after registration, but that didn't seem to work either. I'm not sure what is going on, it could be some other issues in my code for sure.

Ok let's check your end. If you enable debug and trigger message from 3rd party, can you see any logs that PushReceiver is receiving data?

tsightler commented 4 months ago

No, I never see any data received. Last night I decided to give @aracna/fcm library a try since it uses a somewhat different method for registering with Firebase. Unfortunately, it behaves pretty much exactly the same, I can register and connect, but never receive any messages. It seems clear that I'm using the correct parameters to register because if I change any single property value, the registration fails with various errors (not found, unauthorized, etc, based on what specific value is incorrect).

This indicated to me that there was something else I was missing, so I did some additional reverse engineering on the 3rd party app and noticed a property in the metadata that appears to be a recent change. This property is sent along with the FCM token to the app and appears to be indicating use of a new push notification method. I'm thinking that perhaps the API on the sending side has to change as well for the client to be able to receive message, and this parameter may be instructing the server side app to use the new API. I'm going to try that at some point in the next few days.

Regardless, as far as I can see, push-receiver is working as expected, and it's not up to you to help me reverse engineer receiving push notifications for some 3rd party tool, so I'm going to go ahead and close this as the initial issue is resolved, VAPID seems to be required to successfully register and can no longer be the default VAPID. Thanks for your help!