I am trying to verify the x-sendbird-signature in a webhook request using python. I have followed the documentation as well as this post but nothing I have tried is generating the correct signature.
Here is my code
sig = request.headers.get("X-Sendbird-Signature")
api_key = str(django_settings.SENDBIRD_API_TOKEN).encode("utf8")
# NOTE: being verbose here so I can mess around with the data being passed to hmac
data = r"{}".format(request.data) # NOTE: this is pulled from the referenced forum ticket link above
new_data = str(data).encode("utf8")
signature_to_compare = hmac.new(
key=api_key, msg=new_data, digestmod=hashlib.sha256,
).hexdigest()
return signature_to_compare == sig
data is being printed out as
{'category': 'open_channel:message_send', 'silent': False, 'custom_type': '', 'mention_type': 'users', 'mentioned_users': [], 'app_id': '767EBC26-B17E-4E59-9CF3-2D6045F48C62', 'sender_ip_addr': '54.156.5.93', 'type': 'ADMM', 'payload': {'created_at': 1606160253790, 'message': '{"type": "ASSIGNMENT_UPDATED", "assignment": {"id": 392910, "assignedTicket": 884513, "agent": {"id": 488, "displayName": "Ammar Mian", "role": "AGENT", "status": "ACTIVE", "connection": "ONLINE", "email": "ammar.mian08@gmail.com", "photoThumbnailUrl": "", "tier": "INTERMEDIATE", "phoneNumber": null}, "assignedAt": "2020-11-19T14:35:49.686687Z", "responsedAt": null, "endedAt": null, "status": "NOT_RESPONSED", "unreadCount": 57, "responseTime": null}}', 'data': '', 'message_id': 6615908978, 'custom_type': ''}, 'channel': {'data': '', 'channel_url': 'ticket_info_58574dd9_ba06_4985_8b45_57c3977335ce', 'name': 'SENDBIRD_DESK_OPEN_CHANNEL', 'custom_type': 'SENDBIRD_DESK_CHANNEL_CUSTOM_TYPE'}, 'sdk': 'API'}
and the new_data variable returns
b'{\'category\': \'open_channel:message_send\', \'silent\': False, \'custom_type\': \'\', \'mention_type\': \'users\', \'mentioned_users\': [], \'app_id\': \'767EBC26-B17E-4E59-9CF3-2D6045F48C62\', \'sender_ip_addr\': \'54.156.5.93\', \'type\': \'ADMM\', \'payload\': {\'created_at\': 1606160253790, \'message\': \'{"type": "ASSIGNMENT_UPDATED", "assignment": {"id": 392910, "assignedTicket": 884513, "agent": {"id": 488, "displayName": "Ammar Mian", "role": "AGENT", "status": "ACTIVE", "connection": "ONLINE", "email": "ammar.mian08@gmail.com", "photoThumbnailUrl": "", "tier": "INTERMEDIATE", "phoneNumber": null}, "assignedAt": "2020-11-19T14:35:49.686687Z", "responsedAt": null, "endedAt": null, "status": "NOT_RESPONSED", "unreadCount": 57, "responseTime": null}}\', \'data\': \'\', \'message_id\': 6615908978, \'custom_type\': \'\'}, \'channel\': {\'data\': \'\', \'channel_url\': \'ticket_info_58574dd9_ba06_4985_8b45_57c3977335ce\', \'name\': \'SENDBIRD_DESK_OPEN_CHANNEL\', \'custom_type\': \'SENDBIRD_DESK_CHANNEL_CUSTOM_TYPE\'}, \'sdk\': \'API\'}'
This is my current way of trying it, though I have replicated the exact code recommended in the webhook documentation for python to no avail. I have tried every API key available to me, though I know that the master key is the one you are requiring.
Any help you can offer will be appreciated