Skip to content
GitHub

Lexigram-Auth API

lexigram-auth — Authentication and authorisation for the Lexigram platform.

Section titled “lexigram-auth — Authentication and authorisation for the Lexigram platform.”

Admin contributor for lexigram-auth — surfaces session, token, and login

Section titled “Admin contributor for lexigram-auth — surfaces session, token, and login”

Jinja2 widget renderer for auth admin widgets.

Section titled “Jinja2 widget renderer for auth admin widgets.”

JWT token binding configuration and helpers.

Section titled “JWT token binding configuration and helpers.”

Token creation mixin for :class:~lexigram.auth.authn.jwt.JWTTokenManager.

Section titled “Token creation mixin for :class:~lexigram.auth.authn.jwt.JWTTokenManager.”

Token verification and lifecycle mixin for :class:~lexigram.auth.authn.jwt.JWTTokenManager.

Section titled “Token verification and lifecycle mixin for :class:~lexigram.auth.authn.jwt.JWTTokenManager.”

Account verification service for Lexigram Auth.

Section titled “Account verification service for Lexigram Auth.”

Google OAuth verification and claim normalization helpers.

Section titled “Google OAuth verification and claim normalization helpers.”

LDAP authentication manager implementation.

Section titled “LDAP authentication manager implementation.”

MFA utilities - TOTP (RFC 6238) and backup codes

Section titled “MFA utilities - TOTP (RFC 6238) and backup codes”
  • def _int_to_bytes(i: int) -> bytes

Minimal WebAuthn / Passkeys helper (server-side operations)

Section titled “Minimal WebAuthn / Passkeys helper (server-side operations)”
  • class _PendingStore:

    Abstract pending store with optional async cache backend.

    Section titled “Abstract pending store with optional async cache backend.”
    init(self, cache: CacheBackendProtocol | None = None) -> None
    • def init(self, cache: CacheBackendProtocol | None = None) -> None
    • async def set(self, key: str, value: dict, ttl: int = 300) -> None
    • async def get(self, key: str) -> dict | None
    • async def delete(self, key: str) -> None

Argon2id-based password hashing implementations.

Section titled “Argon2id-based password hashing implementations.”

Persistent token revocation store backed by a CacheBackendProtocol.

Section titled “Persistent token revocation store backed by a CacheBackendProtocol.”
  • @dataclass(init=False)

  • class LoginRequest: email: str = Field(…) password: str = Field(…) remember_me: bool = Field(…)

  • @dataclass(init=False)

  • class RegisterRequest: name: str = Field(…) email: str = Field(…) password: str = Field(…) confirm_password: str = Field(…) profile: dict = Field(default_factory=…)

  • @dataclass(init=False)

  • class RefreshTokenRequest: refresh_token: str = Field(…)

  • @dataclass(init=False)

  • class PasswordResetRequest: email: str = Field(…)

  • @dataclass(init=False)

  • class PasswordResetConfirm: token: str = Field(…) new_password: str = Field(…) confirm_password: str = Field(…)

  • @dataclass(init=False)

  • class OAuth2AuthorizeRequest: response_type: str = Field(…) client_id: str = Field(…) redirect_uri: str | None = Field(…) scope: str = Field(…) state: str | None = Field(…)

  • @dataclass(init=False)

  • class OAuth2TokenRequest: grant_type: str = Field(…) code: str | None = Field(…) redirect_uri: str | None = Field(…) client_id: str | None = Field(…) client_secret: str | None = Field(…) refresh_token: str | None = Field(…)

  • @dataclass(init=False)
  • class TokenResponse: access_token: str = Field(…) token_type: str = Field(…) expires_in: int = Field(…) refresh_token: str | None = Field(…) user: dict = Field(…)
  • @dataclass(init=False)
  • class UserProfile: user_id: str name: str email: str created_at: datetime is_active: bool = True is_verified: bool = False updated_at: datetime | None = None last_login_at: datetime | None = None login_count: int = 0 roles: list[str] = Field(default_factory=…) permissions: list[str] = Field(default_factory=…) profile: dict = Field(default_factory=…)

Password security utilities using Passlib with a lightweight fallback.

Section titled “Password security utilities using Passlib with a lightweight fallback.”
  • global DUMMY_PASSWORD_HASH

Authentication services for user login, registration, and token management.

Section titled “Authentication services for user login, registration, and token management.”

User management services for CRUD operations.

Section titled “User management services for CRUD operations.”

Authorization (AuthZ) - Permissions and access control

Section titled “Authorization (AuthZ) - Permissions and access control”
  • def getattr(name: str) -> Any

  • def dir() -> list[str]

Authorization check mixin for AuthorizationService.

Section titled “Authorization check mixin for AuthorizationService.”

Value parser classes for authorization service.

Section titled “Value parser classes for authorization service.”

Authorization guards and route protection decorators.

Section titled “Authorization guards and route protection decorators.”

Unified Authorization Service for Lexigram.

Section titled “Unified Authorization Service for Lexigram.”
  • def getattr(name: str) -> Any
  • class AuthGuardGenerator:
    • def generate(self, name: str, **options: Any) -> GenerationResult

CLI shell context factories for lexigram-auth.

Section titled “CLI shell context factories for lexigram-auth.”
  • global ENV_PREFIX: str = ‘LEX_AUTH__’

  • global ENV_NESTED_DELIMITER: str = ’__’

  • global DEFAULT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 30

  • global DEFAULT_REFRESH_TOKEN_EXPIRE_DAYS: int = 7

  • global DEFAULT_TOKEN_ALGORITHM: str = ‘HS256’

  • global DEFAULT_TOKEN_TYPE: str = ‘Bearer’

  • global DEFAULT_JWT_KEY_ROTATION_GRACE_PERIOD_SECONDS: int = 3600

  • global DEFAULT_MIN_PASSWORD_LENGTH: int = 8

  • global DEFAULT_MAX_PASSWORD_LENGTH: int = 128

  • global DEFAULT_PASSWORD_HASH_ROUNDS: int = 12

  • global DEFAULT_SESSION_TIMEOUT_MINUTES: int = 60

  • global DEFAULT_SESSION_COOKIE_NAME: str = ‘session’

  • global DEFAULT_SESSION_COOKIE_SECURE: bool = True

  • global DEFAULT_SESSION_COOKIE_HTTPONLY: bool = True

  • global DEFAULT_TOTP_DIGITS: int = 6

  • global DEFAULT_TOTP_INTERVAL: int = 30

  • global DEFAULT_TOTP_VALID_WINDOW: int = 1

Convenience provider that registers the full authentication + authorisation stack.

Section titled “Convenience provider that registers the full authentication + authorisation stack.”

Admin DI provider: registers AuthAdminContributor.

Section titled “Admin DI provider: registers AuthAdminContributor.”

di/sub_providers/authentication_provider.py

Section titled “di/sub_providers/authentication_provider.py”

Authentication provider - handles user authentication only.

Section titled “Authentication provider - handles user authentication only.”

di/sub_providers/authorization_provider.py

Section titled “di/sub_providers/authorization_provider.py”

Authorization provider - handles role-based access control and permissions.

Section titled “Authorization provider - handles role-based access control and permissions.”

Google OAuth provider — first-class Google token verification support.

Section titled “Google OAuth provider — first-class Google token verification support.”

MFA provider - handles multi-factor authentication only.

Section titled “MFA provider - handles multi-factor authentication only.”

OAuth2 provider - handles OAuth2/OIDC integration only.

Section titled “OAuth2 provider - handles OAuth2/OIDC integration only.”

OAuth provider config helpers for provider presets.

Section titled “OAuth provider config helpers for provider presets.”

Passkey provider - handles WebAuthn/Passkey support only.

Section titled “Passkey provider - handles WebAuthn/Passkey support only.”

Session provider — registers SessionManagerImpl in the DI container.

Section titled “Session provider — registers SessionManagerImpl in the DI container.”

Token management provider - handles JWT tokens only.

Section titled “Token management provider - handles JWT tokens only.”

Auth domain events emitted by key authentication operations.

Section titled “Auth domain events emitted by key authentication operations.”

Root hook payload surface for lexigram-auth.

Section titled “Root hook payload surface for lexigram-auth.”

Lifecycle hooks for auth/mfa — intercepted when MFA operations occur.

Section titled “Lifecycle hooks for auth/mfa — intercepted when MFA operations occur.”

MFA Manager — consolidated TOTP and backup-code management.

Section titled “MFA Manager — consolidated TOTP and backup-code management.”

RFC 6238 TOTP test vectors for testing without pyotp.

Section titled “RFC 6238 TOTP test vectors for testing without pyotp.”
  • @dataclass(init=False)
  • class AuthToken: token: str = Field(…) expires_at: datetime = Field(…) refresh_token: str | None = None refresh_expires_at: datetime | None = None token_type: str = Field(…)
  • @dataclass(init=False)

  • class UserCredentials:

    user_id: str = Field(…) hashed_password: str | None = None previous_hashes: list[str] = Field(default_factory=…)

  • @dataclass(init=False)

  • class User:

    User model representing an authenticated user.

    Section titled “User model representing an authenticated user.”

    user_id: str = Field(default_factory=…) email: str = ” name: str | None = None is_active: bool = True is_verified: bool = False is_superuser: bool = False roles: list[str] = Field(default_factory=…) permissions: list[str] = Field(default_factory=…) profile: dict[str, Any] = Field(default_factory=…) created_at: datetime | None = Field(default_factory=…) updated_at: datetime | None = Field(default_factory=…) last_login_at: datetime | None = None login_count: int = 0 delegations: list[Any] = Field(default_factory=…) _request_metadata: dict[str, Any] = Field(default_factory=…)

Authentication and authorization module for dependency injection.

Section titled “Authentication and authorization module for dependency injection.”

Condition evaluators for ABAC Policy Engine.

Section titled “Condition evaluators for ABAC Policy Engine.”

In-memory policy store for development and testing.

Section titled “In-memory policy store for development and testing.”

Policy store protocols for ABAC policy persistence.

Section titled “Policy store protocols for ABAC policy persistence.”

Core types for Lexigram ABAC Policy Engine.

Section titled “Core types for Lexigram ABAC Policy Engine.”

Authentication service using Result pattern for error handling.

Section titled “Authentication service using Result pattern for error handling.”

Session-cookie authentication backend for SSR admin flows.

Section titled “Session-cookie authentication backend for SSR admin flows.”

Lifecycle hooks for auth/session — intercepted when session operations occur.

Section titled “Lifecycle hooks for auth/session — intercepted when session operations occur.”

Cached user store implementation for performance optimization

Section titled “Cached user store implementation for performance optimization”

Database-backed user store implementations.

Section titled “Database-backed user store implementations.”

In-memory session store for development and testing.

Section titled “In-memory session store for development and testing.”

OAuth identity storage for linking users to OAuth providers.

Section titled “OAuth identity storage for linking users to OAuth providers.”

Session store protocols for abstracting session storage.

Section titled “Session store protocols for abstracting session storage.”

User and token storage interfaces and implementations

Section titled “User and token storage interfaces and implementations”

GuardProtocol services for authorization in Lexigram Framework

Section titled “GuardProtocol services for authorization in Lexigram Framework”
  • def _get_request_resolver(request: Any) -> Any | None

  • async def _get_request_context_user_id(request: Any) -> str | None

Authentication middleware for web applications

Section titled “Authentication middleware for web applications”

Session validation utilities for authentication middleware.

Section titled “Session validation utilities for authentication middleware.”

Rate-limiting middleware for authentication endpoints.

Section titled “Rate-limiting middleware for authentication endpoints.”

Token caching utilities for authentication middleware.

Section titled “Token caching utilities for authentication middleware.”

Token extraction utilities for authentication middleware.

Section titled “Token extraction utilities for authentication middleware.”