Plugin and configuration¶
Public plugin facade and configuration dataclasses exported from litestar_auth.plugin, plus shared configuration helpers from litestar_auth.config.
ApiKeyConfig is the plugin-owned API-key feature switch. When enabled=True, it participates in
backend resolution, request-scoped store binding, controller registration, validation, and OpenAPI
security scheme generation. apiKeyAuth is registered for the bearer/header API-key transport;
apiKeyHmacAuth is registered only when signing support is configured.
litestar_auth.plugin
¶
Litestar plugin/orchestrator facade for wiring the auth library into an app.
LitestarAuth(config)
¶
Bases: InitPlugin, CLIPlugin
Main auth orchestrator that wires middleware, controllers, and DI.
Store the plugin configuration and validate the requested setup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LitestarAuthConfig[UP, ID]
|
Fully specified plugin configuration (session factory, backends, user manager factory, optional OAuth/TOTP settings). |
required |
Source code in litestar_auth/plugin.py
on_app_init(app_config)
¶
Register auth middleware, controllers, and dependencies on the app.
Returns:
| Type | Description |
|---|---|
AppConfig
|
The updated application config. |
Source code in litestar_auth/plugin.py
on_cli_init(cli)
¶
Register plugin-owned CLI commands without affecting app startup wiring.
Source code in litestar_auth/plugin.py
OAuthProviderConfig(name, client)
dataclass
¶
One entry in :attr:~litestar_auth._plugin.config.OAuthConfig.oauth_providers.
Plugin-owned OAuth routes use name as the {provider} segment (for example
GET {auth_path}/oauth/{name}/callback). client must be an httpx-oauth-compatible
OAuth2 client instance (typically :class:httpx_oauth.oauth2.BaseOAuth2).
The client field is typed as :class:object so core modules do not require a hard
dependency on httpx-oauth at import time.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Logical provider name used in URLs and |
client |
object
|
OAuth2 client instance passed through to the OAuth service layer. |
__post_init__()
¶
coerce(value)
classmethod
¶
Return value when it is already an :class:OAuthProviderConfig.
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in litestar_auth/config.py
litestar_auth.config
¶
Central configuration helpers for litestar-auth.
This module contains small, shared primitives used across the library to keep security-relevant validation consistent, including secret-length checks and explicit unsafe-testing overrides.
OAuthProviderConfig(name, client)
dataclass
¶
One entry in :attr:~litestar_auth._plugin.config.OAuthConfig.oauth_providers.
Plugin-owned OAuth routes use name as the {provider} segment (for example
GET {auth_path}/oauth/{name}/callback). client must be an httpx-oauth-compatible
OAuth2 client instance (typically :class:httpx_oauth.oauth2.BaseOAuth2).
The client field is typed as :class:object so core modules do not require a hard
dependency on httpx-oauth at import time.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Logical provider name used in URLs and |
client |
object
|
OAuth2 client instance passed through to the OAuth service layer. |
__post_init__()
¶
coerce(value)
classmethod
¶
Return value when it is already an :class:OAuthProviderConfig.
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in litestar_auth/config.py
SecretRoleValues(verification_token_secret, reset_password_token_secret, login_identifier_telemetry_secret=None, totp_secret_key=None, totp_pending_secret=None, totp_recovery_code_lookup_secret=None, oauth_flow_cookie_secret=None, api_key_hash_secret=None, api_key_secret_encryption_key=None)
dataclass
¶
Configured secret material grouped by the auth role each value protects.
as_role_pairs()
¶
Return role metadata paired with the configured secret material.
Source code in litestar_auth/_secret_roles.py
require_password_length(password, minimum_length=DEFAULT_MINIMUM_PASSWORD_LENGTH, *, maximum_length=MAX_PASSWORD_LENGTH)
¶
Raise when a password falls outside the configured length bounds.
The default minimum_length matches the password-length metadata exposed
for app-owned user schemas via litestar_auth.schemas.UserPasswordField.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in litestar_auth/config.py
resolve_trusted_proxy_setting(*, trusted_proxy)
¶
Validate and normalize trusted-proxy configuration flags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trusted_proxy
|
object
|
Candidate trusted-proxy value from configuration. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Normalized trusted-proxy boolean. |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If |
Source code in litestar_auth/config.py
validate_oauth_provider_name(name, *, label='OAuth provider name')
¶
Validate and return a route/cookie/callback-safe OAuth provider name.
Returns:
| Type | Description |
|---|---|
str
|
The validated provider name. |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If |
Source code in litestar_auth/config.py
validate_production_secret(secret, *, label, unsafe_testing=False, minimum_length=MINIMUM_SECRET_LENGTH, minimum_entropy_bits=MINIMUM_SECRET_ENTROPY_BITS)
¶
Validate production secret material, preserving explicit test shortcuts.
Production token, HMAC, and encryption secrets need both a length floor and
a basic entropy floor. Repeated-character strings such as "a" * 32 pass
length-only validation but are not safe signing or encryption material.
unsafe_testing=True keeps fixture-only shortcuts possible while making
the weaker posture explicit at the call site.
Source code in litestar_auth/config.py
validate_secret_length(secret, *, label, minimum_length=MINIMUM_SECRET_LENGTH)
¶
Validate the configured secret length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secret
|
str
|
Secret value to validate. |
required |
label
|
str
|
Human-readable label used in error messages. |
required |
minimum_length
|
int
|
Minimum length in characters. |
MINIMUM_SECRET_LENGTH
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When |
Source code in litestar_auth/config.py
validate_secret_roles_are_distinct(role_values)
¶
Raise when one configured secret value is reused across distinct auth roles.
Distinct JWT audiences already keep verification, reset-password, and TOTP tokens scoped to their own flows. Production deployments must still keep those secrets separate so one compromise does not widen the blast radius across multiple roles.
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If one configured secret value is reused across multiple roles. |
Source code in litestar_auth/_secret_roles.py
validate_secret_strength(secret, *, label, minimum_length=MINIMUM_SECRET_LENGTH, minimum_entropy_bits=MINIMUM_SECRET_ENTROPY_BITS)
¶
Validate that a configured secret clears length and Shannon-entropy floors.
The base library checks length only at constructor seams to keep test
fixtures interchangeable with production config. validate_secret_strength
is the recommended operator-side gate for production deployments: wire it
into the application's startup hook (or a custom LitestarAuthConfig
bootstrap path) to fail closed on degenerate inputs like "a" * 32,
keyboard-mashed strings, or other low-entropy material that the chars-count
check alone cannot reject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secret
|
str
|
Secret value to validate. |
required |
label
|
str
|
Human-readable label used in error messages. |
required |
minimum_length
|
int
|
Minimum length in characters (defaults to
:data: |
MINIMUM_SECRET_LENGTH
|
minimum_entropy_bits
|
float
|
Minimum approximate Shannon entropy in bits
(defaults to :data: |
MINIMUM_SECRET_ENTROPY_BITS
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When |