I use NodeJs with Express. I looked the code in https://glitch.com/edit/#!/tf-webhook-receiver?path=server.js%3A1%3A0 .
I think, He convert req.body from raw data as buffer (binary) to string and send to method that create Hmac-sha256 and then base 64.
I can not use bodyParser.raw({ type: 'application/json' }) from example link in each router because I register app.use(express.json) in application layer, it mean my whole project will receive req as JSON Object.
So I do by using some concept in example code by trying to convert req.body being object to JSON String and finally convert to buffer before create hash to compare with req.header('Typeform-Signature').
const encodedJsonObject = Buffer.from(JSON.stringify(req.body, null, 0));
const hash = crypto.createHmac('sha256',TYPEFORM_SECRET)
.update(encodedJsonObject)
.digest('base64');
or
const encodedJsonObject = Buffer.from(JSON.stringify(req.body));
const hash = crypto.createHmac('sha256', TYPEFORM_SECRET)
.update(encodedJsonObject)
.digest('base64');
It still don’t work even thought at .(update) I directly to put JSON.stringify(req.body).
How should I do? or Am I doing something wrong?