0

Trying to push a message from my server - to a web client, using webpush, with this in Nodejs on the server.

webpush.sendNotification(body, 'Your Push Payload Text').then(console.log);

body is a string with the params needed according to: https://github.com/web-push-libs/web-push

{"endpoint":"https://android.googleapis.com/gcm/send/eeXCuiNccV4:APA91bEC-ddg6Iy9OUjtDHzcjFd30cBM_6etyclYe63FrBP_UTCOA_oCwwDhrw-ILp1VqjdQD34X-G4WQ4xNUKnafTz4mGJZcppOsp-_HRNUHRgKXaAdppgClo2JsDAXZQjqxdGd0wq3","keys":{"p256dh":"BE3z-LbXeW65M6xdFhkhbFY9tj_re7RjEIUZDBPOslT1MqIG7-vaxHoUeZY3JOgJ_EaLa1eoifzNX3mno2PgCNc=","auth":"ZYov_VdiE2KZU65wpJWi8Q=="}}

getting this error:

{ WebPushError: Received unexpected response code
12:42 AM
    at IncomingMessage.<anonymous> (/app/node_modules/web-push/src/web-push-lib.js:274:20)
12:42 AM
    at emitNone (events.js:91:20)
12:42 AM
    at IncomingMessage.emit (events.js:185:7)
12:42 AM
    at endReadableNT (_stream_readable.js:974:12)
12:42 AM
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
12:42 AM
    at process._tickCallback (internal/process/next_tick.js:98:9)
12:42 AM
  name: 'WebPushError',
12:42 AM
  message: 'Received unexpected response code',
12:42 AM
  statusCode: 400,
12:42 AM
  headers: 
12:42 AM
   { 'content-type': 'text/html; charset=UTF-8',
12:42 AM
     date: 'Tue, 17 Jan 2017 06:42:38 GMT',
12:42 AM
     expires: 'Tue, 17 Jan 2017 06:42:38 GMT',
12:42 AM
     'cache-control': 'private, max-age=0',
12:42 AM
     'x-content-type-options': 'nosniff',
12:42 AM
     'x-frame-options': 'SAMEORIGIN',
12:42 AM
     'x-xss-protection': '1; mode=block',
12:42 AM
     server: 'GSE',
12:42 AM
     'alt-svc': 'quic=":443"; ma=2592000; v="35,34"',
12:42 AM
     'accept-ranges': 'none',
12:42 AM
     vary: 'Accept-Encoding',
12:42 AM
     connection: 'close' },
12:42 AM
  body: '<HTML>\n<HEAD>\n<TITLE>UnauthorizedRegistration</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>UnauthorizedRegistration</H1>\n<H2>Error 400</H2>\n</BODY>\n</HTML>\n',
12:42 AM
  endpoint: 'https://android.googleapis.com/gcm/send/eeXCuiNccV4:APA91bEC-ddg6Iy9OUjtDHzcjFd30cBM_6etyclYe63FrBP_UTCOA_oCwwDhrw-ILp1VqjdQD34X-G4WQ4xNUKnafTz4mGJZcppOsp-_HRNUHRgKXaAdppgClo2JsDAXZQjqxdGd0wq3' }
C B
  • 12,482
  • 5
  • 36
  • 48

1 Answers1

0

You are getting a 400 Bad Request, make sure that your VAPID keys are matching.

The server should hold both the public key and the private key, and the app should hold only the public key.

Make sure that you only generate the keypair one time.

You can use this page to generate a keypair: https://web-push-codelab.glitch.me/

Kanjo
  • 1