Types and protocols
Runtime-checkable Protocol definitions and type aliases used across transports, strategies, and user models.
litestar_auth.types
Shared typing primitives and authentication protocols.
GuardedUserProtocol
Bases: UserProtocol[ID], Protocol[ID]
Protocol for user models that support account-state guards.
StrategyProtocol
Bases: Protocol[UP, ID]
Protocol describing how auth tokens map to users.
destroy_token(token, user)
async
Invalidate a token for strategies that keep server-side state.
Source code in litestar_auth/types.py
| async def destroy_token(self, token: str, user: UP) -> None:
"""Invalidate a token for strategies that keep server-side state."""
|
read_token(token, user_manager)
async
Resolve a user from a transport token.
Source code in litestar_auth/types.py
| async def read_token(self, token: str | None, user_manager: object) -> UP | None:
"""Resolve a user from a transport token."""
|
write_token(user)
async
Create a token for a given user.
Source code in litestar_auth/types.py
| async def write_token(self, user: UP) -> str:
"""Create a token for a given user."""
|
TotpUserProtocol
Bases: UserProtocol[ID], Protocol[ID]
Protocol for user models that support TOTP 2FA.
TransportProtocol
Bases: Protocol
Protocol describing how auth tokens move in and out of requests.
read_token(connection)
async
Extract a login token from an incoming connection.
Source code in litestar_auth/types.py
| async def read_token(self, connection: ASGIConnection[Any, Any, Any, Any]) -> str | None:
"""Extract a login token from an incoming connection."""
|
set_login_token(response, token)
Persist a login token on an outgoing response.
Source code in litestar_auth/types.py
| def set_login_token(self, response: Response[Any], token: str) -> Response[Any]:
"""Persist a login token on an outgoing response."""
|
set_logout(response)
Clear any transport-specific authentication state.
Source code in litestar_auth/types.py
| def set_logout(self, response: Response[Any]) -> Response[Any]:
"""Clear any transport-specific authentication state."""
|
UserProtocol
Bases: Protocol[ID]
Protocol for user models handled by the library.