Principal¶
crudauth.Principal
dataclass
¶
Principal(
user_id: Any,
scopes: tuple[str, ...] = (),
transport: str = "",
user: Any = None,
is_superuser: bool = False,
email_verified: bool = False,
metadata: dict[str, Any] = dict(),
)
An authenticated identity, independent of which transport authenticated it.
Every transport (session, bearer, api key, ...) returns the same shape,
keyed by user_id. Narrowing transports never changes the identity model.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
Any
|
Immutable identity handle (the user's primary key). |
scopes |
tuple[str, ...]
|
Flat capability scopes carried by this credential. Session principals carry empty scopes in v1; bearer/api-key principals carry whatever was issued. |
transport |
str
|
Name of the transport that authenticated this request
( |
user |
Any
|
The resolved user row (your |
is_superuser |
bool
|
Whether the user holds the superuser flag. |
email_verified |
bool
|
Whether the user's email is verified. |
Example
has_scopes
¶
True if this principal's scopes are a superset of required.