Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing sendNotification gives error except for a certain key pair. #906

Open
2 of 7 tasks
drelit opened this issue Sep 19, 2024 · 0 comments
Open
2 of 7 tasks

Doing sendNotification gives error except for a certain key pair. #906

drelit opened this issue Sep 19, 2024 · 0 comments

Comments

@drelit
Copy link

drelit commented Sep 19, 2024

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
  • 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

  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant