Guards¶
litestar_auth.guards
¶
Public authorization guard exports.
Guards enforce authentication and coarse account state (active, verified,
superuser) on Litestar routes. They are intended for use in route guards=
lists and compose with application-specific authorization policies.
is_active(connection, _handler)
¶
Ensure the authenticated user is active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
ASGIConnection[Any, Any, Any, Any]
|
Incoming ASGI connection (Litestar request scope). |
required |
_handler
|
BaseRouteHandler
|
Route handler being guarded; unused but required by Litestar guard signature. |
required |
Raises:
| Type | Description |
|---|---|
NotAuthorizedException
|
Raised when no authenticated user is attached to the connection. |
PermissionDeniedException
|
Raised when the user does not expose guard account state, or is inactive. |
Source code in litestar_auth/guards/_guards.py
is_authenticated(connection, _handler)
¶
Ensure the request has an authenticated user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
ASGIConnection[Any, Any, Any, Any]
|
Incoming ASGI connection (Litestar request scope). |
required |
_handler
|
BaseRouteHandler
|
Route handler being guarded; unused but required by Litestar guard signature. |
required |
Raises:
| Type | Description |
|---|---|
NotAuthorizedException
|
Raised when no authenticated user is attached to the connection. |
Source code in litestar_auth/guards/_guards.py
is_superuser(connection, _handler)
¶
Ensure the authenticated user has superuser privileges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
ASGIConnection[Any, Any, Any, Any]
|
Incoming ASGI connection (Litestar request scope). |
required |
_handler
|
BaseRouteHandler
|
Route handler being guarded; unused but required by Litestar guard signature. |
required |
Raises:
| Type | Description |
|---|---|
NotAuthorizedException
|
Raised when no authenticated user is attached to the connection. |
PermissionDeniedException
|
Raised when the user is missing account state, or lacks superuser privileges. |
Source code in litestar_auth/guards/_guards.py
is_verified(connection, _handler)
¶
Ensure the authenticated user has a verified account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
ASGIConnection[Any, Any, Any, Any]
|
Incoming ASGI connection (Litestar request scope). |
required |
_handler
|
BaseRouteHandler
|
Route handler being guarded; unused but required by Litestar guard signature. |
required |
Raises:
| Type | Description |
|---|---|
NotAuthorizedException
|
Raised when no authenticated user is attached to the connection. |
PermissionDeniedException
|
Raised when the user is missing account state, or is unverified. |