Skip to main content

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 -- JwtCredentialValidator fills 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 (cedar extra) -- PolicyEngine over cedarpy, with check_authz() and filter_authz() as one-line gates for handlers and list operations.
  • Pluggable resolvers -- slots for domain-specific Cedar resource attributes and principal enrichment.
  • Token issuance -- TokenIssuer for services that mint their own tokens rather than only validating someone else's.
  • Extensions -- AuthnExtension and AuthzExtension do 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

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

sonnet_auth-0.3.1.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

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

sonnet_auth-0.3.1-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

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

Hashes for sonnet_auth-0.3.1.tar.gz
Algorithm Hash digest
SHA256 bbb62a5bdfdda73333480e0242e4022d774e6713487023556241b2d6cf35ef8a
MD5 9de62fac2d31cf18b3dc60038ea750a8
BLAKE2b-256 3da5f31fe60b88e3ab030f3ffe8fc0f565205b654ec71f40497e66a9aa8c9ff1

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonnet_auth-0.3.1.tar.gz:

Publisher: publish.yml on petrarca/sonnet-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for sonnet_auth-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ae053b58c7c865a8187036265d40cf28cb1825e28bc5bba128a65f51e256a24
MD5 0932859e49d765f0917ee89323d037e3
BLAKE2b-256 bcaec78e554b396110e97c36c0eb19bd4f52652c26a562f009417835cb9b3f79

See more details on using hashes here.

Provenance

The following attestation bundles were made for sonnet_auth-0.3.1-py3-none-any.whl:

Publisher: publish.yml on petrarca/sonnet-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page