예제 #1
0
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)
예제 #2
0
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
예제 #3
0
파일: client.py 프로젝트: zdavep/ngx_hawk
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
예제 #4
0
파일: piss_cli.py 프로젝트: dephraser/piss
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