M
M
Madion2017-01-30 10:09:31
Node.js
Madion, 2017-01-30 10:09:31

Why does sending a push notification to GCM return an error: Error 400 UnauthorizedRegistration?

I'm using nodejs + web-push 3.2.1 to send push notifications to the browser.
In firefox at endpoint https://updates.push.services.mozilla.com/wpush/v1/... the notifications go away.
But when trying to send to chrome, opera browsers, it gives an error:
UnauthorizedRegistration.

name: 'WebPushError',
  message: 'Received unexpected response code',
  statusCode: 400,
  headers:
   { 'content-type': 'text/html; charset=UTF-8',
     date: 'Mon, 30 Jan 2017 06:53:51 GMT',
     expires: 'Mon, 30 Jan 2017 06:53:51 GMT',
     'cache-control': 'private, max-age=0',
     'x-content-type-options': 'nosniff',
     'x-frame-options': 'SAMEORIGIN',
     'x-xss-protection': '1; mode=block',
     server: 'GSE',
     'alt-svc': 'quic=":443"; ma=2592000; v="35,34"',
     'accept-ranges': 'none',
     vary: 'Accept-Encoding',
     connection: 'close' },

Added manifest.json to the site root and added a tag with a link to it on the site pages.
Here is the code for sending the push notification:
webPush.setGCMAPIKey('XxxxSyB_cXXXXXdKDfkorOkn3hwYC2xx8aQxxxx'); 

var payload = JSON.stringify({
    title: 'notification title',
    message: 'message body'
});

const pushSubscription = {
    endpoint: "https://android.googleapis.com/gcm/send/............",
    keys: {
        p256dh: "........",
        auth: "......."
    }
};

webPush.sendNotification(pushSubscription, payload).then(function(res) {
    // console.log of stuff
}).catch(function(error) {
    console.log(error);
    process.exit(1);
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question