sonnet-auth
JWT/JWKS authentication and Cedar authorization for sonnet-server applications. Two independent layers: authentication answers who is calling, authorization answers may they do this. You can adopt either without the other.
Version 0.3.0.
What it provides
- JWT/JWKS validation --
JwtCredentialValidatorfills sonnet-server's credential-validator slot. RS256/ES256, TTL-based key refresh, graceful degradation when the identity provider is unreachable. - Ambient identity -- middleware that publishes the caller for the whole request path, so services never take an auth argument.
- Claim mapping -- configurable dot-path extraction from JWT claims onto the auth context and Cedar principal attributes, with an automatic mode for non-plumbing claims.
- Cedar policy evaluation (
cedarextra) --PolicyEngineover cedarpy, withcheck_authz()andfilter_authz()as one-line gates for handlers and list operations. - Pluggable resolvers -- slots for domain-specific Cedar resource attributes and principal enrichment.
- Token issuance --
TokenIssuerfor services that mint their own tokens rather than only validating someone else's. - Extensions --
AuthnExtensionandAuthzExtensiondo the wiring: settings resolution, validator installation, policy loading, DI registration.
There is no user store, no login endpoint and no role model. Those are facts about your application.
Install
uv add sonnet-auth # authentication only
uv add "sonnet-auth[cedar]" # authentication + Cedar authorization
| Extra | Adds | Use when |
|---|---|---|
cedar |
cedarpy |
Evaluating policies, registering AuthzExtension, or mounting whoami_router. |
cedar is the only non-development extra; it carries a compiled Rust engine, so
a verify-only service should not pay for it. The Cedar names are resolved
lazily, so import sonnet_auth never imports cedarpy.
Requires Python 3.14+ and sonnet-server>=0.4.0. The JWKS fetch uses
httpx2, not httpx.
Usage
Register the extensions in your app factory; order matters, because authorization reads the settings authentication resolved.
from sonnet_auth import AuthnExtension, AuthzExtension
registry = create_extension_registry(
DatabaseExtension(),
AuthnExtension(env_prefix="EXAMPLE_", seed_fn=load_auth_seed),
AuthzExtension(loader=load_policies, on_engine_ready=register_resolver),
RestExtension(),
)
Configuration then comes from EXAMPLE_AUTHN_* and EXAMPLE_AUTHZ_*
environment variables, optionally seeded from the database. Gating a handler is
one call:
from sonnet_auth import check_authz
check_authz("search", "Source", source_name)
The usage guides cover authentication, authorization, writing Cedar policies, issuing tokens and MCP wiring.
Documentation
- Usage --
docs/usage/index.md - Design --
docs/design/index.md - Workspace --
../../docs/README.md
License
Apache 2.0 -- see LICENSE.md.
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 sonnet_auth-0.3.1.tar.gz.
File metadata
- Download URL: sonnet_auth-0.3.1.tar.gz
- Upload date:
- Size: 27.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbb62a5bdfdda73333480e0242e4022d774e6713487023556241b2d6cf35ef8a
|
|
| MD5 |
9de62fac2d31cf18b3dc60038ea750a8
|
|
| BLAKE2b-256 |
3da5f31fe60b88e3ab030f3ffe8fc0f565205b654ec71f40497e66a9aa8c9ff1
|
Provenance
The following attestation bundles were made for sonnet_auth-0.3.1.tar.gz:
Publisher:
publish.yml on petrarca/sonnet-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sonnet_auth-0.3.1.tar.gz -
Subject digest:
bbb62a5bdfdda73333480e0242e4022d774e6713487023556241b2d6cf35ef8a - Sigstore transparency entry: 2567955751
- Sigstore integration time:
-
Permalink:
petrarca/sonnet-server@8fb257794749ed1922438cbfb5ef82eeb548d71d -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/petrarca
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8fb257794749ed1922438cbfb5ef82eeb548d71d -
Trigger Event:
push
-
Statement type:
File details
Details for the file sonnet_auth-0.3.1-py3-none-any.whl.
File metadata
- Download URL: sonnet_auth-0.3.1-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ae053b58c7c865a8187036265d40cf28cb1825e28bc5bba128a65f51e256a24
|
|
| MD5 |
0932859e49d765f0917ee89323d037e3
|
|
| BLAKE2b-256 |
bcaec78e554b396110e97c36c0eb19bd4f52652c26a562f009417835cb9b3f79
|
Provenance
The following attestation bundles were made for sonnet_auth-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on petrarca/sonnet-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sonnet_auth-0.3.1-py3-none-any.whl -
Subject digest:
4ae053b58c7c865a8187036265d40cf28cb1825e28bc5bba128a65f51e256a24 - Sigstore transparency entry: 2567955970
- Sigstore integration time:
-
Permalink:
petrarca/sonnet-server@8fb257794749ed1922438cbfb5ef82eeb548d71d -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/petrarca
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8fb257794749ed1922438cbfb5ef82eeb548d71d -
Trigger Event:
push
-
Statement type: