Hello all,
I hope you are doing well.
I have been trying to implement the HMAC authentication system with my incoming webhooks from Jira to my Node JS program. However, I have been getting problems doing so: a lot of the HMAC authentication fails and some fail.
I think it has something to do with the way Node JS is parsing the body of the incoming post request
This is my code:
var bodyParser = require('body-parser')
app.use(bodyParser.json()) // I have tried to use other parameters such as extended
app.post('pathForWebhook', (req,res) =>{
const hmac = createHmac('sha256',process.env.JIRA_HMAC_TOKEN)
hmac.update(Buffer.from(JSON.stringify(req.body), 'utf8'));
let digest = hmac.digest('hex');
digest = 'sha256=' + digest
console.log(JSON.stringify(req.body))
logger.verbose('Digest is: ' +digest)
logger.verbose('REQ ' + req.headers["x-hub-signature"])
})
Best
Antonio