Skip to content

Commit 1812cb4

Browse files
authored
Merge pull request #192 from pusher/fix-extratokens-issue
Fix extra tokens issue
2 parents ba64416 + a2a0d42 commit 1812cb4

File tree

5 files changed

+40
-31
lines changed

5 files changed

+40
-31
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Changelog
22

3+
## 5.1.3
4+
5+
[FIXED] Parsing of the extraTokens in webhook's isValid method
6+
37
## 5.1.2
48

5-
- [CHANGED] Add types/node-fetch to dependencies.
9+
- [CHANGED] Add types/node-fetch to dependencies.
10+
611
## 5.1.1-beta (2022-06-01)
712

813
[FIXED] Updated typescript types with new user features.
@@ -90,7 +95,7 @@ const pusher = new Pusher.forURL(process.env.PUSHER_URL, {
9095

9196
## 2.2.1 (2019-07-03)
9297

93-
no-op release to fix the description on https://www.npmjs.com/package/pusher
98+
no-op release to fix the description on <https://www.npmjs.com/package/pusher>
9499

95100
## 2.2.0 (2018-11-26)
96101

lib/token.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ const util = require("./util")
77
* @param {String} key app key
88
* @param {String} secret app secret
99
*/
10-
function Token(key, secret) {
11-
this.key = key
12-
this.secret = secret
13-
}
14-
15-
/** Signs the string using the secret.
16-
*
17-
* @param {String} string
18-
* @returns {String}
19-
*/
20-
Token.prototype.sign = function (string) {
21-
return crypto
22-
.createHmac("sha256", this.secret)
23-
.update(Buffer.from(string))
24-
.digest("hex")
25-
}
26-
27-
/** Checks if the string has correct signature.
28-
*
29-
* @param {String} string
30-
* @param {String} signature
31-
* @returns {Boolean}
32-
*/
33-
Token.prototype.verify = function (string, signature) {
34-
return util.secureCompare(this.sign(string), signature)
10+
class Token {
11+
constructor(key, secret) {
12+
this.key = key
13+
this.secret = secret
14+
}
15+
/** Signs the string using the secret.
16+
*
17+
* @param {String} string
18+
* @returns {String}
19+
*/
20+
sign(string) {
21+
return crypto
22+
.createHmac("sha256", this.secret)
23+
.update(Buffer.from(string))
24+
.digest("hex")
25+
}
26+
/** Checks if the string has correct signature.
27+
*
28+
* @param {String} string
29+
* @param {String} signature
30+
* @returns {Boolean}
31+
*/
32+
verify(string, signature) {
33+
return util.secureCompare(this.sign(string), signature)
34+
}
3535
}
3636

3737
module.exports = Token

lib/webhook.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const errors = require("./errors")
2+
const Token = require("./token")
23

34
/** Provides validation and access methods for a WebHook.
45
*
@@ -46,7 +47,10 @@ WebHook.prototype.isValid = function (extraTokens) {
4647

4748
const tokens = [this.token].concat(extraTokens)
4849
for (const i in tokens) {
49-
const token = tokens[i]
50+
let token = tokens[i]
51+
if (token instanceof Token === false) {
52+
token = new Token(token.key, token.secret)
53+
}
5054
if (this.key == token.key && token.verify(this.body, this.signature)) {
5155
return true
5256
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pusher",
33
"description": "Node.js client to interact with the Pusher Channels REST API",
4-
"version": "5.1.2",
4+
"version": "5.1.3",
55
"author": "Pusher <[email protected]>",
66
"contributors": [
77
{

0 commit comments

Comments
 (0)