I have added a secret, while creating a webhook for a form. now in the callback API, m fetching Authorization in the header as the secret value. But I am not getting the secret. How will we get the secret in the callback.
Answered
secret in webhook.
Best answer by picsoung
Hey
Could you tell us which programming language you use?
Here is an example that works in Node with express
const express = require("express");
const app = express();
const crypto = require('crypto')
app.use(express.raw({ type: 'application/json' }));
app.post('/webhook', async (request, response) => {
console.log('~> webhook received');
// security check, let's make sure request comes from typeform
const signature = request.headers['typeform-signature']
const isValid = verifySignature(signature, request.body.toString());
if (!isValid) {
throw new Error('Webhook signature is not valid, someone is faking this!');
}
// send 200 status back, and notify typeform 👌
response.sendStatus(200)
const { event_type, form_response } = JSON.parse(request.body);
// filter response events only
if (event_type === 'form_response') {
// LOGIC goes here
}
});
// function to verify request signature
const verifySignature = function(receivedSignature, payload){
const hash = crypto
.createHmac('sha256', webhookSecret)
.update(payload)
.digest('base64')
return receivedSignature === `sha256=${hash}`
}
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.