Last active
December 17, 2015 02:08
-
-
Save ozten/5533555 to your computer and use it in GitHub Desktop.
Early PyHawk client sample
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 hawk | |
import requests | |
credentials = { | |
'id': 'dh37fgj492je', | |
'key': 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', | |
'algorithm': 'sha256' | |
} | |
url = 'http://127.0.0.1:8002/resource/1?b=1&a=2' | |
params = {'b': 1, 'a': 2} | |
client = hawk.Client() | |
# Hawk header call | |
header = client.header(url, 'GET', { 'credentials': credentials, | |
'ext': 'and welcome!' }) | |
headers = [('Authorization', header['field'])] | |
# Using the /resource/1 Web Service | |
res = requests.get(url, data=params, headers=headers) | |
response = { | |
'headers': res.headers | |
} | |
# Hawk authenticate call | |
if client.authenticate(response, credentials, header['artifacts'], | |
{ 'payload': res.text }): | |
print "Yay, server response is verified" | |
else: | |
print "Can't trust it, no no no no" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment