Skip to main content

A Requests auth module for HTTP Signature

Project description

requests-http-signature is a Requests authentication plugin (requests.auth.AuthBase subclass) implementing the IETF HTTP Signatures draft RFC. It has no required dependencies outside the standard library. If you wish to use algorithms other than HMAC (namely, RSA and ECDSA algorithms specified in the RFC), there is an optional dependency on cryptography.

Installation

$ pip install requests-http-signature

Usage

import requests
from requests_http_signature import HTTPSignatureAuth

preshared_key_id = 'squirrel'
preshared_secret = 'monorail_cat'
url = 'http://example.com/path'

requests.get(url, auth=HTTPSignatureAuth(key=preshared_secret, key_id=preshared_key_id))

By default, only the Date header is signed (as per the RFC) for body-less requests such as GET. The Date header is set if it is absent. In addition, for requests with bodies (such as POST), the Digest header is set to the SHA256 of the request body and signed (an example of this appears in the RFC). To add other headers to the signature, pass an array of header names in the header keyword argument.

In addition to signing messages in the client, the class method HTTPSignatureAuth.verify() can be used to verify incoming requests:

def key_resolver(key_id, algorithm):
    return 'monorail_cat'

HTTPSignatureAuth.verify(request, key_resolver=key_resolver)

Asymmetric key algorithms (RSA and ECDSA)

For asymmetric key algorithms, you should supply the private key as the key parameter to the HTTPSignatureAuth() constructor as bytes in the PEM format:

with open('key.pem', 'rb') as fh:
    requests.get(url, auth=HTTPSignatureAuth(algorithm="rsa-sha256", key=fh.read(), key_id=preshared_key_id))

When verifying, the key_resolver() callback should provide the public key as bytes in the PEM format as well:

License

Licensed under the terms of the Apache License, Version 2.0.

https://travis-ci.org/kislyuk/requests-http-signature.png https://codecov.io/github/kislyuk/requests-http-signature/coverage.svg?branch=master https://img.shields.io/pypi/v/requests-http-signature.svg https://img.shields.io/pypi/l/requests-http-signature.svg https://readthedocs.org/projects/requests-http-signature/badge/?version=latest

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-http-signature-0.0.3.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requests_http_signature-0.0.3-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file requests-http-signature-0.0.3.tar.gz.

File metadata

File hashes

Hashes for requests-http-signature-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bf7ce03e48d33dc140ef736d297380d2c783ecfc973c11a51bfee5334d7aaad4
MD5 86073faa8b0f276b96ad89608eded608
BLAKE2b-256 c6991db0d30a5b42a9ef64c94d29697ea5a3a38533697b3cc0d374e3b3d33224

See more details on using hashes here.

File details

Details for the file requests_http_signature-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for requests_http_signature-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e8b0824c918b38d59d64c9e60a0be2d699854c429da8e435a99d7510e0b9c3f0
MD5 3480c1354ace51051988e9ec4f5f4c87
BLAKE2b-256 2a11ccb4da6099d9c452ccbc2c9b660a14234343c20a4ba86aa885e211188091

See more details on using hashes here.

Supported by

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