Skip to content

Commit 3805a28

Browse files
authored
Mention the correct default contentEncoding (aes128gcm) in the README (#576)
Also, avoid base64-decoding a key which is then re-encoded later.
1 parent f3f53a9 commit 3805a28

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ request only. This overrides any API key set via `setGCMAPIKey()`.
184184
- **TTL** is a value in seconds that describes how long a push message is
185185
retained by the push service (by default, four weeks).
186186
- **headers** is an object with all the extra headers you want to add to the request.
187-
- **contentEncoding** is the type of push encoding to use (e.g. 'aesgcm', by default, or 'aes128gcm').
187+
- **contentEncoding** is the type of push encoding to use (e.g. 'aes128gcm', by default, or 'aesgcm').
188188
- **proxy** is the [HttpsProxyAgent's constructor argument](https://github.com/TooTallNate/node-https-proxy-agent#new-httpsproxyagentobject-options)
189189
that may either be a string URI of the proxy server (eg. http://< hostname >:< port >)
190190
or an "options" object with more specific properties.

src/vapid-helper.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ function getVapidHeaders(audience, subject, publicKey, privateKey, contentEncodi
187187
validatePublicKey(publicKey);
188188
validatePrivateKey(privateKey);
189189

190-
publicKey = urlBase64.decode(publicKey);
191190
privateKey = urlBase64.decode(privateKey);
192191

193192
if (expiration) {
@@ -215,13 +214,13 @@ function getVapidHeaders(audience, subject, publicKey, privateKey, contentEncodi
215214

216215
if (contentEncoding === WebPushConstants.supportedContentEncodings.AES_128_GCM) {
217216
return {
218-
Authorization: 'vapid t=' + jwt + ', k=' + urlBase64.encode(publicKey)
217+
Authorization: 'vapid t=' + jwt + ', k=' + publicKey
219218
};
220219
}
221220
if (contentEncoding === WebPushConstants.supportedContentEncodings.AES_GCM) {
222221
return {
223222
Authorization: 'WebPush ' + jwt,
224-
'Crypto-Key': 'p256ecdsa=' + urlBase64.encode(publicKey)
223+
'Crypto-Key': 'p256ecdsa=' + publicKey
225224
};
226225
}
227226

0 commit comments

Comments
 (0)