Zendesk Webhook Authorization in Python
I am using following link as guide for me to authorize the api I am configuring in my Zendesk webhook:
and I am writing a code equivalent to the this function in python isValidSignature(signature, body, timestamp) but I am not able to get an hmac signature that is matching signature submitted to me in my headers :
def isValidSignature(signature, body, timestamp):
key = webHookSecret.encode('utf-8')
hmac_result = hmac.new(key, (timestamp+body).encode('utf-8'), hashlib.sha256)
hmac_result = hmac_result.digest()
if signature == str(base64.b64encode(hmac_result), 'utf-8'):
Please advise what should I modify to fix this issue?
Can you try adding this to your code and see if that gets it working?
webHookSignature = base64.b64decode(signature.encode('utf-8'))
if webHookSignature == str(base64.b64encode(hmac_result), 'utf-8'):
Tipene Hughes implementing those lines gives me the following output :
The problem might be the Zendesk webhook I am using , How Can I get the right webhook that must me used in the Hmac?
I don't think this is necessarily an issue with the webhook you're using. I've gone ahead and put together an example that might be helpful to you. Take a look through this and see if you're able to identify what might be causing the error on your end.
If you continue to run in to errors, let me know and we can pull this in to a ticket so I can take a look at your code in more detail.
Hi Tipene .,
Thank you for your reply !
My issue was how I submitted the body variable to the function , As I was reading json from the request , I was not getting the raw Body (ex. body = req.get_body() in Azure Functions )
Your example helped me to think about the issue , Thank alot
Glad to hear you've got it working!
Have a great day :)
Please sign in to leave a comment.