Skip to main content

simple_module_auth

Pluggable authentication core for simple_module apps. Owns the stable public contracts every other module imports — UserContext, the AuthProvider protocol, the PrincipalResolver chain, and the get_current_user / CurrentUser dependencies — plus the AuthMiddleware that resolves the current principal on every request.

Heads up: for most apps you don't install this directly — an auth-provider module (simple_module_users for email+password, simple_module_keycloak for OIDC) pulls it in and registers itself on app.state.auth.auth_provider.

Install

pip install simple_module_auth

What it provides

  • UserContext — the request-scoped principal (id, name, email, roles).
  • AuthProvider protocol — the swappable-backend contract (resolve_user, get_login_url, get_logout_url, is_bearer_request); exactly one provider module registers an implementation on app.state.auth.auth_provider.
  • PrincipalResolver chain — async (Request) -> UserContext | None callables apps append to app.state.auth.principal_resolvers (e.g. PAT/bearer-token or API-key auth), consulted after the session path.
  • AuthMiddleware — delegates to the provider + resolver chain on every request and populates the request principal.
  • get_current_user / CurrentUser dependency.
  • auth.oidc_common — provider-neutral OIDC helpers (JWKS/JWT validation, refresh-token sealing, sign-in rotation, renewal, cache persistence, directory) shared by the oidc and keycloak modules.
  • Anonymous-access is declared via the framework's method-aware register_public_routes hook (with the SM_AUTH_PUBLIC_PATHS host-level escape hatch).

Usage

from fastapi import APIRouter

from auth.web.deps import CurrentUser

router = APIRouter()


@router.get("/me")
async def me(user: CurrentUser):
    return {"user_id": user.id, "email": user.email}

Routes that need a specific permission use RequiresPermission from hosting:

from fastapi import Depends

from simple_module_hosting.permissions import RequiresPermission

from .constants import PERM_PRODUCTS_CREATE


@router.post("/", dependencies=[Depends(RequiresPermission(PERM_PRODUCTS_CREATE))])
async def create_product(): ...

auth.web.deps.require_permission is deprecated and will be removed in 0.1.0 (#698). It retains its legacy any-of semantics, role-based admin bypass and cached permission check. Migrate to RequiresPermission(PERM_KEY); for several required permissions, declare a dependency for each. Unlike the legacy helper, RequiresPermission rechecks administrators demoted during the request.

Depends on

  • simple_module_core, simple_module_db
  • itsdangerous

License

MIT — see LICENSE.

Metadata

Release files for simple-module-auth 0.0.47

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

Source distribution (sdist)

Source distribution for simple-module-auth 0.0.47
File Size Uploaded Provenance Actions
simple_module_auth-0.0.47.tar.gz 42.4 kB With provenance Details for simple_module_auth-0.0.47.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-module-auth 0.0.47
File Interpreter ABI Platform Actions
simple_module_auth-0.0.47-py3-none-any.whl Python 3 none any Details for simple_module_auth-0.0.47-py3-none-any.whl

Total release size: 77.3 kB

Release files / simple_module_auth-0.0.47.tar.gz

Download URL simple_module_auth-0.0.47.tar.gz
Size 42.4 kB
Tags Source
SHA-256 checksum
How to use checksums
eecccf7c4c1d5b467ed53dcde66f1d27cefb5c977fcc7242e4bbfec0871c33d7
BLAKE2b-256 checksum
How to use checksums
b07d5d39ac782fde7ba7c1c53fbc05f9734c2c9b9d04388b7f1c6390e8293ad6
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 16, 2026.

Transparency log

Release files / simple_module_auth-0.0.47-py3-none-any.whl

Download URL simple_module_auth-0.0.47-py3-none-any.whl
Size 34.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa9f8549d24a5153c5a044d9d3a916ceaf48e0126beb193cd321fa4e5ba7bb9c
BLAKE2b-256 checksum
How to use checksums
826fc0f534135f9b11578270f2d31ef43f837b39487fc4a00f22d8b2254c1e55
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 16, 2026.

Transparency log

Security for simple-module-auth 0.0.47

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 simple_module_auth-0.0.47.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 16, 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.

Release history Release notifications | RSS feed

This release

0.0.47 This release

2 release files Full provenance

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