Skip to content

Commit

Permalink
Fix "Authentication token is not verified" problem (#116)
Browse files Browse the repository at this point in the history
* Refactor generateHashV2 for empty body handling

Update generateHashV2 function to handle empty body and improve payload construction.

* fix: body.length problem
  • Loading branch information
ecebeci authored Jan 15, 2024
1 parent 85480b8 commit 5499fca
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 5499fca

Please sign in to comment.