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 headers 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://github.com/pyauth/requests-http-signature/workflows/Python%20package/badge.svg 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.2.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

requests_http_signature-0.2.0-py2.py3-none-any.whl (9.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: requests-http-signature-0.2.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.7

File hashes

Hashes for requests-http-signature-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b121d66a0e7d8d3ea5679b39405b9dcf79fd2e099f8cbf33a10abe9e89c2c50b
MD5 2be1b9d5df79e888c5c7a94b36f8ec00
BLAKE2b-256 274a7a2c85c19f7f45ca73ef1dd53e8c6fc3eef471fe5a6d92877bf9abe96cd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: requests_http_signature-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.7

File hashes

Hashes for requests_http_signature-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 850672f64b1481ffd406a7a30572fa2f3336e5ee8ff2ff53a6c1544bee66c479
MD5 90b0618447203a0c9005a8c5fde34179
BLAKE2b-256 6f149ec1bbba469db810c70b190093eba61da48a7ab1df6d14462c0f9b39c810

See more details on using hashes here.

Supported by

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