Last active
April 9, 2019 08:13
-
-
Save thewheat/98024f005d618ae16249 to your computer and use it in GitHub Desktop.
Process Intercom's Webhook with Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Don't forget to modify urls.py accordingly to allow routing to the function | |
# url(r'', views.index) | |
from django.views.decorators.csrf import csrf_exempt | |
import hashlib | |
import hmac | |
from django.http import HttpResponse | |
@csrf_exempt | |
def index(request): | |
KEY = "YOUR_HUB_SECRET" | |
if request.method == "POST" : | |
SIGNATURE = request.META.get('HTTP_X_HUB_SIGNATURE') | |
MESSAGE = request.body | |
calculated = hmac.new(KEY, MESSAGE, hashlib.sha1).hexdigest() | |
calculated = "sha1=" + (calculated) | |
print "Found : " + SIGNATURE | |
print "Generated : " + calculated | |
if calculated == SIGNATURE: | |
print " YES! " | |
else: | |
print " No..... =( " | |
return HttpResponse() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment