bartbutenaers / node-red-contrib-ui-web-push

A Node-RED widget node to send web push notifications via the dashboard
Apache License 2.0
16 stars 5 forks source link

Unable to send notification to subscribers #7

Closed vicvega83 closed 3 years ago

vicvega83 commented 3 years ago

Hi, I'm trying to implement the Basic example flow, and, despite having the warning: Unknown context store 'storeInFile' specified. Using default store. (but persistent context appears to work just ok, as I can see the folder it creates to store informations, and also I can inspect its contents in the dedicated tab (below) context

But other than that, I cannot receive the notifications. the node says:

pushnode

Is there a more indepth log I can inspect to address the issue ? Thank you, and great job!

bartbutenaers commented 3 years ago

Hi @vicvega83,

There should indeed be some extra logging added, because now troubleshooting is difficult. And there is a lot of things that could go wrong in such a long chain...

When having a quick look, there are 'at least' two things that need to be solved.

Note that these need to be solved in Maxim's node, not in this UI node. I will try to contact Maxim, to ask him how we can proceed with this. Because I am not sure if he is still maintaining his node ...

1. Show failure descriptions

As soon as there are failures (like in your case), those failures need to be logged via node.error to make sure they appear in the debug sidebar. That allows you to see what is going wrong, and a Catch-node can be used to monitor these failures in a flow.

2. Avoid swallowing exceptions

I have noticed that in the node-red-contrib-web-push nodes, sometimes the exceptions are being swallowed. Perhaps this happens in multiple places, but at the moment I have only detected the below case. Perhaps this goes a bit too much into detail for you, but it is a reminder for me how it works...

  1. I add an "xxxx" at the end of "p256dh", to make sure I have an invalid subscription:

    image

    Note that adding "xxxx" at the end of "auth" doesn't result in a failure?

  2. This will result in an exception, which is catched in the web-push.js file:

    image

  3. However at line 45 the error text (string) is converted to an empty javascript object. Which means from here on the exception will disappear...

  4. As a result, the "failed" property is undefined, so the exception won't be registered as a failure at line 67 (instead it will be registered as a succes on line 61):

    image

  5. This means that the node status will report "1 send, 0 failures" ...

vicvega83 commented 3 years ago

Hi Bart, thanks for the time and the effort. I get your point, even if this is a different scenario with a different outcome, that's where the exceptons are lost. Please let me know if I can help testing in order to troubleshoot the issue. Thanks again.

bartbutenaers commented 3 years ago

@vicvega83, To be able to create pull requests for Maxim, I need to understand a bit more how his library works. It would be very useful if you could help me with this!

  1. Can you try to find the web-push.js file. In my case it is in the folder C:\Users\Gebruiker.node-red\node_modules\node-red-contrib-web-push

  2. And could you insert the statement console.log("current = " + JSON.stringify(current)) at this location in that file:

    image

  3. Run your test again. Since you have 2 failures, there should be 2 error lines logged (starting with "current = " ...).

  4. Please share those error log lines here.

Thanks!!!!!

vicvega83 commented 3 years ago

I'll try that right away

bartbutenaers commented 3 years ago

Thanks!! I think you also need to restart Node-RED between step 3 and 4

vicvega83 commented 3 years ago

You're welcome :) Yes, I do have : current = {"failed":{}} current = {"failed":{}}

bartbutenaers commented 3 years ago

Heuh? Also an empty object, without exception information. Not what I had hoped for...

Could you repeat the same process and add console.log("err = " + err) here please:

image

vicvega83 commented 3 years ago

Ok, looks like we've got something to work on now ! firstly I executed and the log reported: err = Error: Vapid subject is not a url or mailto url. mymail@gmail.com then, after feeling really stupid, and adding "mailto:" to my email address in the vapid configuration , I executed it again, pardon me if it's unreadable and ugly unformatted:

current = {"failed":{"name":"WebPushError","message":"Received unexpected response code","statusCode":403,"headers":{"content-type":"text/plain; charset=utf-8","x-content-type-options":"nosniff","x-frame-options":"SAMEORIGIN","x-xss-protection":"0","date":"Sat, 28 Aug 2021 22:31:41 GMT","content-length":"194","alt-svc":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","connection":"close"},"body":"the key in the authorization header does not correspond to the sender ID used to subscribe this user. Please ensure you are using the correct sender ID and server Key from the Firebase console.\n","endpoint":"https://fcm.googleapis.com/fcm/send/eAzLfIxkZ2k:APA91bH4-PaLpK68Wfd2iUrnHnIsEVYFbVdocX0KXYbjbK_VVA9lB8DOkz_prwzQUlSZG2qxTISc4B3UKk6LlPwsMcFn96VTO4z30Hr2kNwMCiSlJf3NngtxXrOwwQMKV8Ga04HvT9bM"}} current = {"failed":{"name":"WebPushError","message":"Received unexpected response code","statusCode":401,"headers":{"access-control-allow-headers":"content-encoding,encryption,crypto-key,ttl,encryption-key,content-type,authorization","access-control-allow-methods":"POST","access-control-allow-origin":"*","access-control-expose-headers":"location,www-authenticate","content-type":"application/json","date":"Sat, 28 Aug 2021 22:31:41 GMT","server":"nginx","strict-transport-security":"max-age=31536000;includeSubDomains","content-length":"213","connection":"Close"},"body":"{\"code\": 401, \"errno\": 109, \"error\": \"Unauthorized\", \"more_info\": \"http://autopush.readthedocs.io/en/latest/http.html#error-codes\", \"message\": \"Request did not validate missing authorization header: Key mismatch\"}","endpoint":"https://updates.push.services.mozilla.com/wpush/v2/gAAAAABhKrJ1CthdDmLmPalaxmGAt77oKInvy_nZgq3llmaER4ChztSdOSQPUscYnnbtvQM7N2VWK0Pde0F0kuCuyEyETbM84ZEc6k7ggQv1gWPu6pYzcRL0LO53sMuz8JACGMzjS6sLOs-Hbasrd7LclftbC00wJSD8FrT63ktxsVfSBajzsdk"}}

I'm having a look at it as soon as I submit this. Thanks again

bartbutenaers commented 3 years ago

Indeed this makes things much clearer. Thanks !!! It is this kind of information that users should be able to look at, in order to simplify troubleshooting a bit. I will analyse this further and create a pull request to improve this in Maxime's repository. But I'm not sure whether that will arrive on npm soon ...

the key in the authorization header does not correspond to the sender ID used to subscribe this user.

It is already some time ago, but I think this went wrong:

image

At the time being I have added this button to Maxim's config screen, to simplify the process of generating a key pair (without having to use command line tools...). But (if I'm not mistaken) the key pair is generated based on the email address which you have specified. So if the email address is changed, you need to generate a new key pair.

However when you generate a new key, I think that all current subscriptions become invalid. Because they have been made with the old key pair, and are validate using the new key pair.

So I think you need to do this:

  1. Enter a valid email
  2. Generate a new key pair
  3. Remove the current subscriptions (via the Unsubscribe button on your dashboards, or I think you can just remove the subscriptions property from the flow memory via the Context sidebar)
  4. Subscribe again via the dashboard.

My time is up for today ...

vicvega83 commented 3 years ago

Gotcha! Mine's almost up too, thanks for the help, I'll get back to you as soon as I'll make a new attempt. Thanks again!

vicvega83 commented 3 years ago

Hi Bart, after checking that my config nodes had "mailto:email@something.com" and re-generating keys, everything works as intended, Thank you for your support, and I'm happy to be the reason your node is more loggy now :)

On a separate note, I just need to fiddle with certificates, to get rid of the naggy security warning i get everytime I load the dashboard page: Because when I click on the notification message, it brings me to the dashboard url, but it's a blank page, until I refresh the browser, and get the security warning once again to get past.

But that's another topic :) Thanks again.

bartbutenaers commented 3 years ago

@vicvega83, I have created a pull request to fix both log issues.

Can you please create a new issue in this repo, for your certificate issue. Because that is another thing that lots of users might struggle with. So perhaps we can improve that also...

bartbutenaers commented 3 years ago

@vicvega83, FYI: Maxim has been so kind to merge my pull request, and publish version 0.0.3 on npm. When you reinstall my node, you should gets his update. I can't test it now, but will do so tonight.