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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file starlette_hmac-0.0.4.tar.gz.
File metadata
- Download URL: starlette_hmac-0.0.4.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.6 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1b12b14e31a3709a7d2209bb3ab6f1e45c58e324dba57cb5e9e724a3e8e1ed3
|
|
| MD5 |
cffafa64690f3eae561c909c9c120eb0
|
|
| BLAKE2b-256 |
43d14468813227bfc6281d922b9f240878782191a99e210d0d2171a1663a41db
|
File details
Details for the file starlette_hmac-0.0.4-py3-none-any.whl.
File metadata
- Download URL: starlette_hmac-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.6 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e63b69ef21ac7fca39c92f825c9540e78a74fb436431d71c032cdc16b34251a0
|
|
| MD5 |
cea0ae8e40c4ad009055bf20173cea3f
|
|
| BLAKE2b-256 |
3ac1a976b95197a0c0b108a32c1530490a47b32a92f3e196e221c3fa82a9b647
|