This release is a pre-release and may not be stable for production use.
benzene-auth
Authentication middleware for Benzene Python —
Basic auth, JWT/OAuth2 bearer-token validation, and an AWS API Gateway custom authorizer
adapter. Depends only on benzene-core (PyJWT is an optional extra, only for the real JWT decode).
pip install benzene-auth # middleware only
pip install benzene-auth[jwt] # + PyJWT, for JwtValidator's real decode
Authentication is an interception concern, like the core's health endpoint: a middleware verifies the
credential ahead of the message router, attaches the authenticated Principal to the context on
success, and short-circuits with Result.unauthorized on failure — a middleware that does not
await next() ends the pipeline, so the handler never sees an unauthenticated call. Verifiers and
validators may be sync or async, and none of them raise for a bad credential.
from benzene.auth import (
basic_auth_interception,
bearer_token_interception,
JwtValidator,
api_gateway_authorizer,
get_principal,
)
# Basic auth — verify(username, password) → bool | Principal | None.
def verify(username: str, password: str) -> bool:
return password == secrets.get(username)
definition.middleware += [basic_auth_interception(verify, realm="orders")]
# Bearer/OAuth2 — a validator that decodes a JWT (None on any invalid token, never raises).
definition.middleware += [
bearer_token_interception(
JwtValidator(key=signing_secret, algorithms=("HS256",), audience="orders-api")
)
]
# Downstream, read who the caller is:
principal = get_principal(context) # None when unauthenticated
# AWS API Gateway custom authorizer — adapts the same validate seam into a Lambda handler
# emitting an Allow/Deny IAM policy scoped to the invoked methodArn.
handler = api_gateway_authorizer(JwtValidator(key=signing_secret))
- Basic —
basic_auth_interception(verify, *, realm=...)decodesauthorization: Basic base64(user:pass)and callsverify;Trueauthenticates asPrincipal(username), aPrincipalis attached as-is,False/None(or a missing/malformed header) rejects withunauthorized. - Bearer/OAuth2 —
bearer_token_interception(validate, *, scheme="Bearer")reads the bearer token and callsvalidate(token) → claims | Principal | None.JwtValidatoris a ready-made validator that decodes a JWT with PyJWT (imported lazily), constrained by key, algorithms, audience, and issuer, returningNonefor any token it rejects.static_token_validator({token: principal})builds an in-memory validator for tests. - API Gateway authorizer —
api_gateway_authorizer(validate, *, principal_id_claim=...)returns a Lambdahandler(event, context=None) → dict. It pulls the token fromauthorizationToken(TOKEN authorizer) or theauthorizationheader (REQUEST authorizer), and returns an IAM policy document allowing or denyingexecute-api:Invokeonevent["methodArn"], echoing the claims undercontext.
Nothing here needs PyJWT installed to run or test: JwtValidator accepts an injected decode
function and static_token_validator needs no JWT library at all. Mirrors .NET's Benzene.Auth.Basic
and Benzene.Auth.OAuth2, plus Benzene.Aws.Lambda.ApiGateway.ApiGatewayCustomAuthorizer, and
contributes the benzene.auth subpackage to the shared benzene namespace.
Metadata
Release files for benzene-auth 0.1.0b2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| benzene_auth-0.1.0b2.tar.gz | 9.4 kB | With provenance | Details for benzene_auth-0.1.0b2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| benzene_auth-0.1.0b2-py3-none-any.whl | Python 3 | none | any | Details for benzene_auth-0.1.0b2-py3-none-any.whl |
Total release size: 22.3 kB
Release files / benzene_auth-0.1.0b2.tar.gz
| Download URL | benzene_auth-0.1.0b2.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7520027b3ceffe6e556a77487d5f46d700aef8cbc2d39c10e2e337b42ebaccb9
|
|
BLAKE2b-256 checksum How to use checksums |
0a6ec342ce869a05e8d3477d179f4c69fe33e17829448fe921dbc67a5939a541
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / benzene_auth-0.1.0b2-py3-none-any.whl
| Download URL | benzene_auth-0.1.0b2-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce18032a062cf75a86ecfec88bf8be34988ff71819e773ee290db0cb57901e23
|
|
BLAKE2b-256 checksum How to use checksums |
6fdd6e9529fcde3d8792968910f46a41c9a81037504649ca8b18487b58ea967d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logSecurity for benzene-auth 0.1.0b2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for benzene_auth-0.1.0b2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.