requests-hawk
Project description
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 across mozilla services projects.
Great, how can I use it?
First, you’ll need to install it:
pip install requests-hawk
Then, in your project, if you know the id and key, you can use:
import requests
from requests_hawk import HawkAuth
hawk_auth = HawkAuth(id='my-hawk-id', key='my-hawk-secret-key')
requests.post("https://example.com/url", auth=hawk_auth)
Or if you need to derive them from the hawk session token, instead use:
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)
In the second example, the server_url parameter to HawkAuth was used to provide a default host name, to avoid having to repeat it for each request.
If you wish to override the default algorithm of sha256, pass the desired algorithm name using the optional algorithm parameter.
Note: The credentials parameter has been removed. Instead pass id and key separately (as above), or pass the existing dict as **credentials.
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.
Run tests
To run test, you can use tox:
tox
CHANGELOG
1.1.0 (2020-12-16)
Allow to skip hashing request and response bodies with always_hash_content.
1.0.1 (2020-01-20)
Add Python 3 support. (#22)
1.0.0 (2015-12-15)
Simplified API for using HawkAuth when the id and key are known. (#8)
Added support for overriding the default algorithm (sha256) when deriving credentials from the hawk session token, via a new algorithm parameter.
See the README for migration advice if you use the credentials parameter.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file requests-hawk-1.1.0.tar.gz
.
File metadata
- Download URL: requests-hawk-1.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a5e61cab14627f1b5ba7de0e3fb2b681007ff7b2a49110d504e5cd6d7fd62d6 |
|
MD5 | c07aaa31a47fabaf48c2935e3ae8a8d5 |
|
BLAKE2b-256 | d8261fde4d22835e3872a5ec5bb6f92aae213147190f7a9dcb7f271e351dae75 |
File details
Details for the file requests_hawk-1.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: requests_hawk-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad9393ec0979067d07a725ccf8c18bfbbbe1f3455df59692bed71462904efe9 |
|
MD5 | bb6cff972f59b37ef974b7856f8bcf76 |
|
BLAKE2b-256 | 120aa9cbd70b619dc6e466d4beb5e83b4703ab04540ca3a25f50e9b9c2bdd937 |