Open FallDi opened 8 years ago
@FallDi did find a solution/reason to this issue? I am experiencing the same error.
I make following changes in file https://github.com/GoogleChrome/web-push-encryption/blob/master/src/push.js
const endpoint = subscription.endpoint.replace(GCM_URL, TEMP_GCM_URL); ----> const endpoint = subscription.endpoint;
and
if (endpoint.indexOf(TEMP_GCM_URL) !== -1) {
if (gcmAuthToken) {
headers.Authorization = `key=${gcmAuthToken}`;
} else {
throw new Error('GCM requires an Auth Token parameter');
}
}
convert to
headers.Authorization = `key=${gcmAuthToken}`;
headers["Content-Type"] = "application/json";
Are you sure your subscription isn't out of date? Can you ensure that the subscription
you pass in is recently created by client-side code?
yep of course. When i change code - push received successfully for same subscription
. It 100% reproduced for any subscription
problem in request forming. Also gcm-http.googleapis.com do not support binary request body. Please see https://developers.google.com/web/updates/2016/03/web-push-encryption
Web Push
Phew! Now that you have an encrypted payload, you just need to make a relatively simple HTTP POST request to the endpoint specified by the user’s subscription.
You need to set three headers.
Encryption: salt=<SALT>
Crypto-Key: dh=<PUBLICKEY>
Content-Encoding: aesgcm
<SALT> and <PUBLICKEY> are the salt and server public key used in the encryption, encoded as URL-safe Base64.
When using the Web Push protocol, the body of the POST is then just the raw bytes of the encrypted message. However, until Chrome and Google Cloud Messaging support the protocol, you can easily include the data in your existing JSON payload as follows.
{
"registration_ids": [ "…" ],
"raw_data": "BIXzEKOFquzVlr/1tS1bhmobZ…"
}
The value of the rawData property must be the base64 encoded representation of the encrypted message.
I'd suggest using this library instead, it's getting more attention than this repo: github.com/web-push-libs/web-push
@gauntface same error with that library as well. ..
Please raise an issue on that library. This one is now deprecated
my script is very simple
In response i got
Root cause: payload must be json and also http response header must contains Content-type:application/json