From 5499fca2c5d702c1b6b2eef886b11348dad6bf1b Mon Sep 17 00:00:00 2001 From: Emre Cebeci <31591904+ecebeci@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:04:21 +0300 Subject: [PATCH] Fix "Authentication token is not verified" problem (#116) * Refactor generateHashV2 for empty body handling Update generateHashV2 function to handle empty body and improve payload construction. * fix: body.length problem --- lib/utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 7435410..8201220 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -22,9 +22,13 @@ var utils = module.exports = { return shaSum.digest('base64'); }, generateHashV2: function (apiKey, separator, uri, randomString, secretKey, body) { + var payload = randomString + uri; + if (Object.keys(body).length > 0) { + payload += JSON.stringify(body) + } var signature = crypto .createHmac('sha256', secretKey) - .update(randomString + uri + JSON.stringify(body)) + .update(payload) .digest('hex'); var authorizationParams = [