Open zmoog opened 1 year ago
Verify that the webhook is coming from Toggl. See Validating Received Events for more information.
Toggl sends a header x-webhook-signature-256
:
{
"host": "eo4sf6wa6nmc4w.m.pipedream.net",
"content-length": "180",
"content-type": "application/json",
"x-webhook-signature-256": "sha256=c466be51dd6b98d0e8f7ce95bf0432da9a16665db925b8b11f2ae76801f115f9",
"accept-encoding": "gzip",
"user-agent": "Go-http-client/2.0"
}
Quick implementation:
def signature_is_valid(secret: str, body: str, signature: str):
"""
Verify if the signature of a webhook request..
Check https://developers.track.toggl.com/docs/webhooks_start/validating_received_events
for more details.
"""
digest = hmac.new(secret.encode("utf-8"), body.encode("utf-8"), hashlib.sha256).hexdigest()
return hmac.compare_digest(signature, f'sha256={digest}')
Bootstrap a new SAM project.