web-push icon indicating copy to clipboard operation
web-push copied to clipboard

Doing sendNotification gives error except for a certain key pair.

Open drelit opened this issue 5 months ago • 0 comments

NOTE: Please test in a least two browsers (i.e. Chrome and Firefox). This helps with diagnosing problems quicker.

Setup

Please provide the following details, the more info you can provide the better.

Operating System: OSX | M2 Node Version: Node.js v20.15.1 web-push Version: "^3.6.7"

Please select any browsers that you are experiencing problems with:

  • [X ] Chrome
  • [X] Firefox
  • [ ] Opera for Android
  • [ ] Samsung Internet Browser
  • [ ] Other

Please list the browsers you are have tested this, including the version of the browser (i.e. Chrome Beta, Firefox Beta etc).

Problem

Please explain what behaviour you are seeing.

In attempts to send a push notification, I am getting

WebPushError: Received unexpected response code
...
  statusCode: 401,
  headers: {
    server: 'nginx',
    date: 'Thu, 19 Sep 2024 16:30:06 GMT',
    'content-type': 'application/json',
    'content-length': '153',
    vary: 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers',
    'strict-transport-security': 'max-age=31536000',
    via: '1.1 google',
    'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'
  },
  body: '{"code":401,"errno":109,"error":"Unauthorized","message":"InvalidSignature","more_info":"http://autopush.readthedocs.io/en/latest/http.html#error-codes"}',
  endpoint: 'https://updates.push.services.mozilla.com/wpush/v2/gAAAAABm6aTthg3Lgo5tIPppHebfwZ62cnzrnFtjeHR9n76VBbNPD3cJeby3BeS0fMuO4BhiZ6xcycXu7CfSphnkWc_TNPqkMYMZZJquJVWBs3d2YmmJlGVHXls2rZgR71YMmRh-zLYJOVatwLO4-Xi-YacaKWJCYqPjZdIIvOn2nXGuzRQryfU'
}

However, using a colleagues pub/priv VAPID keys, it works, regardless of the endpoint. Ive tried generating the vapid keys with:

npx web-push generate-vapid-keys
AND
webPush.generateVAPIDKeys()

Expected

Please explain what you expected to happen

A successful web push notification to the endpoint.

Features Used

  • [X] VAPID Support
  • [ ] GCM API Key
  • [ ] Sending with Payload

Example / Reproduce Case

Please provide a code sample that reproduces the issue. If there is a repository that reproduces the issue please put the link here.

import webPush from "web-push";
console.log("VAPID PUBLIC KEY:", process.env["VAPID_PUBLIC_KEY"])
console.log("VAPID PRIVATE KEY:", process.env["VAPID_PRIVATE_KEY"])
await webPush.sendNotification(
    {
        endpoint: 'https://updates.push.services.mozilla.com/wpush/v2/gAAAAABm6aTthg3Lgo5tIPpp...',
        keys: {
            auth: 'z4OmWpcIYzxYAxFFHls...',
            p256dh: 'BJ-RMwZ5oL0I5MXMtz4aZg8Ss2PBA_UP6yHjW58UVL0wdnWPy8rX5ioB...'
        },
    },
    "TEST",
    {
        vapidDetails: {
            subject: 'mailto:[email protected]',
            publicKey: process.env["VAPID_PUBLIC_KEY"]!,
            privateKey: process.env["VAPID_PRIVATE_KEY"]!,
        }
    }
)

Other

Please put any remaining notes here.

i am executing this code with

npx tsx test-vapid.ts

drelit avatar Sep 19 '24 17:09 drelit