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.
  • API tokens via introspection -- opaque bearer tokens (for clients that cannot run OAuth) validated by asking the issuing token service: RFC 7662 by configuration, or any service through the TokenIntrospector protocol. Cached, and mapped onto the same claims as a JWT.
  • 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.

Metadata

Release files for sonnet-auth 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sonnet-auth 0.4.0
File Size Uploaded Provenance Actions
sonnet_auth-0.4.0.tar.gz 33.6 kB With provenance Details for sonnet_auth-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sonnet-auth 0.4.0
File Interpreter ABI Platform Actions
sonnet_auth-0.4.0-py3-none-any.whl Python 3 none any Details for sonnet_auth-0.4.0-py3-none-any.whl

Total release size: 73.4 kB

Release files / sonnet_auth-0.4.0.tar.gz

Download URL sonnet_auth-0.4.0.tar.gz
Size 33.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f89af039d26f4c5bf6505933c8b3ea57d59000003239ebf31ca3f07513cd45c5
BLAKE2b-256 checksum
How to use checksums
25382cfb882963fdff9183ed898cd20e23677ef895470ab7a6e8a0e697cc4309
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Release files / sonnet_auth-0.4.0-py3-none-any.whl

Download URL sonnet_auth-0.4.0-py3-none-any.whl
Size 39.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1126729c552d54acfb130b5fc501c164ccc4bb4649fb8935e7b90ec3acf7b96b
BLAKE2b-256 checksum
How to use checksums
5f3709fc2a43324eb278d4d23ca552958df5d2fdcc7aee338907b072163b926b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Security for sonnet-auth 0.4.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sonnet_auth-0.4.0.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 Nov 11, 2026.

Transparency log

A 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.

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