Starlette middleware for hmac access key
Project description
starlette-hmac
HMAC Middleware for the pythonic Starlette API framework
Installation
$ pip install starlette-hmac
Usage
This will verify that the request will be done with an authorization
header with value HMAC <hmac hash of body>
import os
from starlette.applications import Starlette
from starlette_hmac.middleware import HMACMiddleware
shared_secret = os.environ.get("SHARED_SECRET")
app = Starlette()
app.add_middleware(HMACMiddleware, shared_secret=shared_secret)
Advanced usage
To customize header name or value of you can pass the needed parameters to the middleware.
This example verifies that the request was done with an x-hub-signature
header with value sha256=<hash>
import os
import hashlib
from starlette.applications import Starlette
from starlette_hmac.middleware import HMACMiddleware
shared_secret = os.environ.get("SHARED_SECRET")
app = Starlette()
app.add_middleware(HMACMiddleware,
shared_secret=shared_secret,
header_field="x-hub-signature",
digestmod=hashlib.sha256,
"header_format"="sha256={}"
)
Develop
This project uses poetry to manage its development environment, and pytest as its test runner. To install development dependencies:
$ poetry install
To run the tests:
$ poetry shell
$ pytest
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
starlette_hmac-0.0.3.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for starlette_hmac-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7014370a9180c459c366592a4689b7088f035e7bcf6e1a7b0edd8f1e152f0576 |
|
MD5 | 0314240e6023a5d77586a26995ad2471 |
|
BLAKE2b-256 | 3f9e2454335d59ef9964d7698b92f833b2c1b3c4fd12cdeedb2219a3b3bb6e0f |