Skip to main content

Session-cookie authentication primitives — middleware, login/logout, redirect helpers for simple_module

Project description

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 / require_permission 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, get_public_paths, 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 and the require_permission(*permissions) dependency factory.
  • 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.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 the require_permission(...) dependency factory:

from fastapi import Depends

from auth.deps import require_permission


@router.post("/", dependencies=[Depends(require_permission("products.create"))])
async def create_product(): ...

Depends on

  • simple_module_core, simple_module_db
  • itsdangerous

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_module_auth-0.0.21.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

simple_module_auth-0.0.21-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file simple_module_auth-0.0.21.tar.gz.

File metadata

  • Download URL: simple_module_auth-0.0.21.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for simple_module_auth-0.0.21.tar.gz
Algorithm Hash digest
SHA256 cf851f6ff07f8962c4831ab38c1200a5cbf18c0ec407d3d79169d7949203465b
MD5 8164a4b2f7317b787980568b4f4484cc
BLAKE2b-256 9ca28e9e1e5416c1e0b9c95859eccc1e1e84490bcb4f87b2f99a9072ed442278

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_module_auth-0.0.21.tar.gz:

Publisher: release.yml on antosubash/simple_module_python

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

File details

Details for the file simple_module_auth-0.0.21-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_module_auth-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 66e4589c0f7f87a47cf1532036b4f408028335b7fb1bfbe804367e36248e64fd
MD5 1261f9ff1bf67174fc47901695f0801b
BLAKE2b-256 e1f515f0058254c4dbde6d7ab05472f9f1bf5556499963bc9049848f0694c892

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_module_auth-0.0.21-py3-none-any.whl:

Publisher: release.yml on antosubash/simple_module_python

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page