Last active
February 28, 2016 01:55
-
-
Save fideloper/136efd2cf9fdb791f445 to your computer and use it in GitHub Desktop.
This file contains 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
# | |
# Externally, create a signed request | |
# | |
import os, base64, hashlib, hmac, requests | |
# Message Signature | |
# METHOD:uri[:extra_params] | |
msg = 'GET:/foo/bar' | |
signature = base64.b64encode(hmac.new(os.environ['SERVEROPS_SECRET'], msg.encode('utf-8'), hashlib.sha256).digest()) | |
url = 'localhost:5000/tail/error' | |
headers = {'Authorization': signature} | |
r = requests.get(url, headers=headers) | |
# | |
# In application, authorize above signed request using SignedRequest object | |
# | |
# This is a Flask request object in this case | |
auth = SignedRequest(request, os.environ['SERVEROPS_SECRET']) | |
if not auth.authorized_request(): | |
print "request rejected" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment