Skip to content

Instantly share code, notes, and snippets.

@ozten
Last active December 17, 2015 02:08
Show Gist options
  • Save ozten/5533555 to your computer and use it in GitHub Desktop.
Save ozten/5533555 to your computer and use it in GitHub Desktop.
Early PyHawk client sample
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