问题
I've been doing a google tutorial on how to send web push notifications on Chrome using web-push node module.
The thing is, the tutorial also provides a companion server app that you are supposed to use in order to test sending push notifications from a server to the client.
But, in both the companion app and even when using web-push cli on my local machine, when trying to send a notification I am getting a "Unauthorized Registration" error. Can't find anything online about this error - what am I doing wrong/ missing?
$ web-push send-notification --endpoint=https://fcm.googleapis.com/fcm/send/<<endpoint-key>>
Error sending push message:
{ [WebPushError: Received unexpected response code]
name: 'WebPushError',
message: 'Received unexpected response code',
statusCode: 400,
headers:
{ 'content-type': 'text/html; charset=UTF-8',
date: 'Fri, 25 Nov 2016 08:54:08 GMT',
expires: 'Fri, 25 Nov 2016 08:54:08 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="36,35,34"',
'accept-ranges': 'none',
vary: 'Accept-Encoding',
connection: 'close' },
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' }
回答1:
Have you used any HTTP server to test the code in that tutorial? Further, DNS should be localhost or https:// site. If you are running the HTTP server under some port, better to have 5 digit client side port. Here is linked my project browser push
回答2:
There's a report of this in the web-push library issue tracker: https://github.com/web-push-libs/web-push/issues/254.
Can you try resetting your clock, like the reporters in that issue did?
回答3:
Check the field gcm_sender_id in your manifest.json file if it matches exactly with the gcm_sender_id in your google account. I faced a similar problem before and this was the solution to my problem.
来源:https://stackoverflow.com/questions/40801235/web-push-api-chrome-returning-unauthorized-registration