Getting 401 Error on my Remote Server but the same code is working fine on my Local Machine
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, node.js
- Área
- api, authentication, backend
Línea de trabajo
Start with server.js at the webPush.sendNotification call and the web-push-lib.js:347 stack location; compare the remote and local runtime configuration, subscription data, and options. Review serviceworker.js and the client subscription flow to determine whether the remote request uses mismatched credentials or sender details. Done means reproducing the failure or identifying the configuration mismatch with a concrete correction.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Setup
Operating System:
Node Version: <12.20.0>
web-push Version: <3.4.5>
Please select any browsers that you are experiencing problems with:
- Chrome
- Firefox
Problem
I'm using Node.js and MongoDB.
I'm getting the following error when I use web-push on my DigitalOcean server:
When I send notification to a Firefox Client, I get the following error:
WebPushError: Received unexpected response code
at IncomingMessage.<anonymous> (/home/sahilnare78/apps/Hola_Peeps_New_Design/node_modules/web-push/src/web-push-lib.js:347:20)
at IncomingMessage.emit (events.js:326:22)
at IncomingMessage.EventEmitter.emit (domain.js:483:12)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
statusCode: 401,
headers: {
'access-control-allow-headers': 'content-encoding,encryption,crypto-key,ttl,encryption-key,content-type,authorization',
'access-control-allow-methods': 'POST',
'access-control-allow-origin': '*',
'access-control-expose-headers': 'location,www-authenticate',
'content-type': 'application/json',
date: 'Sat, 24 Jul 2021 14:55:33 GMT',
server: 'nginx',
'strict-transport-security': 'max-age=31536000;includeSubDomains',
'content-length': '213',
connection: 'Close'
},
body: '{"code": 401, "errno": 109, "error": "Unauthorized", "more_info": "http://autopush.readthedocs.io/en/latest/http.html#error-codes", "message": "Request did not validate missing authorization header: Key mismatch"}',
The important part is this:
body: '{"code": 401, "errno": 109, "error": "Unauthorized", "more_info": "http://autopush.readthedocs.io/en/latest/http.html#error-codes", "message": "Request did not validate missing authorization header: Key mismatch"}',
When I send notification to a Chrome Client, I get the following error:
WebPushError: Received unexpected response code
at IncomingMessage.<anonymous> (/home/sahilnare78/apps/Hola_Peeps_New_Design/node_modules/web-push/src/web-push-lib.js:347:20)
at IncomingMessage.emit (events.js:326:22)
at IncomingMessage.EventEmitter.emit (domain.js:483:12)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
statusCode: 403,
headers: {
'content-type': 'text/plain; charset=utf-8',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '0',
date: 'Sat, 24 Jul 2021 14:55:32 GMT',
'content-length': '194',
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
connection: 'close'
},
body: 'the key in the authorization header does not correspond to the sender ID used to subscribe this user. Please ensure you are using the correct sender ID and server Key from the Firebase console.\n',
Expected
When I tested my code on my local machine, it was working properly. But it doesn't work on my remote server.
Features Used
- VAPID Support
- Sending Notifications
Example / Reproduce Case
Here's the code that I used:
serviceworker.js:
self.addEventListener('push', function(event) {
const payload = event.data ? event.data.json() : 'no payload';
event.waitUntil(
self.registration.showNotification(payload.title, {
body: payload.body,
icon: payload.icon
})
)
});
server.js:
webPush.sendNotification({
endpoint: subscription.endpoint,
keys: {
auth: subscription.auth,
p256dh: subscription.p256dh
},
expirationTime: 12*60*60
}, payload, options)
.then(function() {
res.json({registered: true});
}).catch((err) => console.error(err));
index.html (client side script):
navigator.serviceWorker.ready
.then(function(registration) {
return registration.pushManager.getSubscription()
.then(async function(subscription) {
if (subscription) {
return subscription;
}
const response = await fetch('/api/notification/vapidPublicKey');
const vapidPublicKey = await response.text();
const convertedVapidKey = urlBase64ToUint8Array(vapidPublicKey);
return registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: convertedVapidKey
});
});
}).then(function(subscription) {
fetch('/api/notification/register', {
method: 'post',
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify({
subscription: subscription
}),
});
});
- Lenguaje dominante
- JavaScript
- Estrellas
- 3.6k
- Forks
- 328
- Merge medio
- 11 d 5 h
- PR fusionados (30 d)
- 3
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de web-push-libs/web-push
-
Support AbortSignal in sendNotification()Posiblemente ocupada @rvitaliy la tomó hace 2 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
web-push-libs/web-push#1006 ·
-
[Critical?] Potential Hijack ReportPosiblemente ocupada @marco-c la tomó hace 1 día. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
web-push-libs/web-push#1005 · 1 comentario · 2 reacciones · 1 asignado ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
web-push-libs/web-push#977 ·
-
Does it can be use in China?Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
web-push-libs/web-push#942 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
web-push-libs/web-push#940 · 1 reacción ·
Todos los issues de web-push-libs/web-push
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ImranR98/apps.obtainium.imranr.dev#2000 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
routing: the tray panel's stage stands still with motion reduced while a request is in flightAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
microsoft/monaco-editor#5577 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
obsidianmd/obsidian-help#1169 ·
Los mantenedores suelen responder en 2 días
-
[docs] RELEASE.md: wrong branch name, no check that the prepare PR merged with the right subject, manual publish stepPosiblemente ocupada @albertteoh la tomó hoy. Abiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
jaegertracing/jaeger-ui#4739 ·
Los mantenedores suelen responder en 1 día