def main(): """ Run the sample_client.py from the CLI """ 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} header = hawk_header(url, 'GET', { 'credentials': credentials, 'ext': 'and welcome!' }) headers = [('Authorization', header['field'])] res = requests.get(url, data=params, headers=headers) if (200 != res.status_code): print('Authorized request (FAILED) status=' + str(res.status_code) + ' body=' + res.text) response = {'headers': res.headers} if hawk_authenticate(response, credentials, header['artifacts'], {'payload': res.text}): print("Response validates (OK)") else: print("Response validates (FAIL) " + res.text)
def main(): """ Run the sample_client.py from the CLI """ 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} header = hawk_header(url, 'GET', { 'credentials': credentials, 'ext': 'and welcome!' }) headers = [('Authorization', header['field'])] res = requests.get(url, data=params, headers=headers) if (200 != res.status_code): print 'Authorized request (FAILED) status=' + str(res.status_code) + ' body=' + res.text response = { 'headers': res.headers } if hawk_authenticate(response, credentials, header['artifacts'], { 'payload': res.text }): print "Response validates (OK)" else: print "Response validates (FAIL) " + res.text
def main(): """ Call the hello service from the command line. """ credentials = { 'algorithm': 'sha256', 'id': 'bb190a0c210f', 'key': 'saRgjL5mz305xgKdKm7wtyH3uXbJb1YMtGEFbiGB5kAukFessyq1KiVNJ3rGDPT' } url = 'http://localhost/hello/api/greeting/Hawk' header = hawk_header(url, 'GET', { 'credentials': credentials, 'ext': 'PyHawk!' }) headers = { 'Authorization':header['field'], 'Accept-Version':'~2' } res = requests.get(url, data={}, headers=headers) if (200 != res.status_code): print 'Authorized request (FAILED) status=' + str(res.status_code) + ' body=' + res.text else: print 'status =', res.status_code print 'headers =', res.headers print 'body =', res.text
def get_request_headers(url, method, credentials, etag=None, extra_headers=None): headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } if extra_headers: for key in extra_headers: headers[key] = extra_headers[key] if credentials: header = hawk_header(url, method, { 'credentials': credentials }) headers['Authorization'] = header['field'] if etag: headers['If-Match'] = etag return headers