Created
November 22, 2016 00:18
-
-
Save foxmask/d47ee68d90351ee73060da7555176676 to your computer and use it in GitHub Desktop.
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
import requests | |
import json | |
url = 'http://127.0.0.1:8000/th/api/taiga/webhook/123' | |
headers = { | |
"X-TAIGA-WEBHOOK-SIGNATURE": '5ff287f1565a40de55fbf1809a3781574e828f9c', | |
"X-Hub-Signature": "sha1={}".format('5ff287f1565a40de55fbf1809a3781574e828f9c'), | |
"Content-Type": "application/json" | |
} | |
data = json.dumps({ | |
"type": "test", | |
"by": { | |
"id": 6, | |
"permalink": "http://localhost:9001/profile/user1", | |
"username": "user1", | |
"full_name": "Purificacion Montero", | |
"photo": "//media.taiga.io/avatar.80x80_q85_crop.png", | |
"gravatar_id": "464bb6d514c3ecece1b87136ceeda1da" | |
}, | |
"date": "2016-04-12T12:00:56.335Z", | |
"action": "test", | |
"data": { | |
"test": "test" | |
} | |
} | |
) | |
request = requests.post(url, data=data, headers=headers) | |
print(request) |
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
import hmac | |
import hashlib | |
from rest_framework.response import Response | |
from rest_framework.decorators import api_view | |
def verify_signature(key, data, signature): | |
mac = hmac.new(key.encode("utf-8"), msg=data, digestmod=hashlib.sha1) | |
return mac.hexdigest() == signature | |
@api_view(['POST']) | |
def taiga(request, key): | |
signature = request.META.get('HTTP_X-TAIGA-WEBHOOK-SIGNATURE') # does not work, Header not received :/ | |
print(signature) | |
if verify_signature(key, request.data, signature): | |
return Response({"message": "Success"}) | |
else: | |
return Response({"message": "Failed!"}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTTP_X_TAIGA_WEBHOOK_SIGNATURE does the trick