Skip to main content

Cross-language HMAC-SHA256 request signing with a defined canonical string format.

Project description

hardenlabs-hmac

Cross-language HMAC-SHA256 request signing with a defined canonical string format. Guaranteed identical signatures across C#, Python, TypeScript, and Go.

Installation

pip install hardenlabs-hmac
pip install "hardenlabs-hmac[fastapi]"   # for FastAPI middleware
pip install "hardenlabs-hmac[requests]"  # for requests library support

Quick Start — Server (FastAPI)

from fastapi import FastAPI
from hardenlabs_hmac.config import HmacConfig, HmacClientIdentity, SignedHeadersConfig
from hardenlabs_hmac.middleware.fastapi import HardenHmacMiddleware

config = HmacConfig(
    signed_headers=SignedHeadersConfig.default(),
    timestamp_tolerance_seconds=30,
    clients={
        "order-service": HmacClientIdentity(shared_secret="orders-base64-secret"),
    },
)

app = FastAPI()
app.add_middleware(HardenHmacMiddleware, config=config)

@app.get("/api/hello")
async def hello():
    return {"message": "Authenticated!"}

Quick Start — Client (httpx)

from hardenlabs_hmac.client import HmacClientFactory
from hardenlabs_hmac.config import HmacConfig, HmacTargetConfig

config = HmacConfig(
    targets={
        "my-service": HmacTargetConfig(
            base_url="https://api.example.com",
            shared_secret="your-base64-encoded-secret",
        ),
    },
)

factory = HmacClientFactory(config)
with factory.create_sync_client("my-service") as client:
    response = client.get("/api/hello")  # automatically signed

Quick Start — Client (requests)

from hardenlabs_hmac.client import HmacClientFactory
from hardenlabs_hmac.config import HmacConfig, HmacTargetConfig

config = HmacConfig(
    targets={
        "my-service": HmacTargetConfig(
            base_url="https://api.example.com",
            shared_secret="your-base64-encoded-secret",
        ),
    },
)

factory = HmacClientFactory(config)
with factory.create_requests_session("my-service") as client:
    response = client.get("/api/hello")  # automatically signed

Documentation

Full documentation, canonical string specification, and cross-language compatibility details: github.com/HardenLabs/HardenHMAC

License

Apache License 2.0

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

hardenlabs_hmac-0.1.2.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

hardenlabs_hmac-0.1.2-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file hardenlabs_hmac-0.1.2.tar.gz.

File metadata

  • Download URL: hardenlabs_hmac-0.1.2.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for hardenlabs_hmac-0.1.2.tar.gz
Algorithm Hash digest
SHA256 de9834194b754a340f812161e8c53dba902193d69b3352d0f3fa9ffea1195cb9
MD5 da6273f674a0ca33fcc224ef3a9a6ab8
BLAKE2b-256 8583528c12a0d84785ed9f333f0f1ef00eb8535302f89f035a4f9fe60e091563

See more details on using hashes here.

File details

Details for the file hardenlabs_hmac-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for hardenlabs_hmac-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b9f7685e2798e5f5d7304e36fe6efb708cc195ad63b9dc303b191aec996aa207
MD5 d9a6883bc40d3882774d7ff6435f77d4
BLAKE2b-256 e5eca19656d33acc924c7d2b2a543bcfc45cb3af24e4dd801223aa6e8e6e1794

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