Skip to main content

requests-hawk

Project description

https://travis-ci.org/mozilla-services/requests-hawk.png

This project allows you to use the python requests library with the hawk authentication mechanism.

Hawk itself does not provide any mechanism for obtaining or transmitting the set of shared credentials required, but this project proposes a scheme we use accross mozilla services projects.

Great, how can I use it?

First, you’ll need to install it:

pip install requests-hawk

Then, in your project, you can use it like that:

import requests
from requests_hawk import HawkAuth

hawk_auth = HawkAuth(
    hawk_session=resp.headers['hawk-session-token'],
    server_url=self.server_url
)
requests.post("/url", auth=hawk_auth)

Integration with httpie

Httpie is a tool which lets you do requests to a distant server in a nice and easy way. Under the hood, httpie uses the requests library. We’ve made it simple for you to plug hawk with it.

If you know the id and key, use it like that:

http POST localhost:5000/registration\
--auth-type=hawk --auth='id:key'

Or, if you want to use the hawk session token, you can do as follows:

http POST localhost:5000/registration\
--auth-type=hawk --auth='c0d8cd2ec579a3599bef60f060412f01f5dc46f90465f42b5c47467481315f51:'

Take care, don’t forget to add the extra : at the end of the hawk session token for it to be considered like so.

How are the shared credentials shared?

Okay, on to the actual details.

The server gives you a session token, that you’ll need to derive to get the hawk credentials.

Do an HKDF derivation on the given session token. You’ll need to use the following parameters:

key_material = HKDF(hawk_session, '', 'identity.mozilla.com/picl/v1/sessionToken', 32*2)

The key material you’ll get out of the HKDF needs to be separated into two parts, the first 32 hex characters are the hawk id, and the next 32 ones are the hawk key:

credentials = {
    'id': keyMaterial[0:32]
    'key': keyMaterial[32:64]
    'algorithm': 'sha256'
}

Run tests

To run test, you can use tox:

tox

CHANGELOG

0.2.1 (2015-10-14)

  • Make sure the requests json parameter is handled properly. (#7)

0.2.0 (2015-05-19)

  • Fix encoding error in setup.py with Python 3.4

  • Add a configuration parameter in order to be able to set the timestamp to use.

0.1.2 (2014-08-13)

  • Add Python3 support

0.1.1 (2014-07-21)

  • First version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests-hawk-0.2.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

requests_hawk-0.2.1-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file requests-hawk-0.2.1.tar.gz.

File metadata

  • Download URL: requests-hawk-0.2.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for requests-hawk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c7ddaf87847db29556585daf412d1997c38543bc23f1691151be3de87e0c7746
MD5 104fbd8630e724ddb15a99886caf0ac7
BLAKE2b-256 c6548ead9fe140f0b65021646db83a0e9cc2958b2a85c0119f7697bd180292e5

See more details on using hashes here.

File details

Details for the file requests_hawk-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for requests_hawk-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e77603dfc4800af33b2808c6b6003d1faae5aef9cf1e3988620de3564be8f61a
MD5 0130c6fe593a08949f7b7ceb36c3315d
BLAKE2b-256 a2b97f10fbf6c977e58d150128429413110b7f1a6b6dbd6e458c40673eb45f80

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page