What is your goal?
Authenticate webhook using HMAC
What is the problem & what have you tried?
The webhook passes the HMAC digest in the webhook header. When the option “parse headers” is enabled for webhook, the headers are added as an array to the body of the webhook. To calculate my own HMAC digest for comparison, the Python code is:
digest = hmac.new(secret, msg=data, digestmod=hashlib.sha256).digest()
calculated_signature = base64.b64encode(digest)
So I need to use the body of the webhook in the sha256() function, which I set as
sha256(webhook_bundle;base64;secret;text)
This will always be different since the body of the webhook as changed.
Sample webhook
[
{
"order_number": "webhook_12345",
"partner_order_id": "webhook_12345",
"fulfillment-status": "canceled"
"__IMTHEADERS__": [
{
"name": "x-hmac-sha256",
"value": "JMHimfnNPO0"
}
]
}
]
Is it possible to get the header value without it being added to the body or remove the array during the HMAC calculation?