pub struct IdentityUser {
pub id: String,
pub name: String,
pub email: String,
pub tenant_id: String,
pub roles: Vec<String>,
pub permissions: Vec<String>,
}Expand description
The standard identity a request can carry.
IdentityUser is a read-only projection of IClaims for request
handling — not a persistence entity. When an endpoint needs the raw claim
map, read it through IClaimsExt in middleware or
infrastructure code; IdentityUser covers the identity fields almost every
handler needs.
Put it in a request with #[fromclaim] and the binder fills it from the
authenticated principal:
#[derive(WebxRequestMeta)]
pub struct CreateOrderRequest {
#[fromclaim]
pub user: IdentityUser,
pub sku: String,
}The handler then reads req.user.id, req.user.tenant_id or
req.user.is_in_role("admin") without touching the token or the context.
#[fromclaim(optional)] viewer: Option<IdentityUser> makes the endpoint work
for anonymous callers too; anonymous access must be declared explicitly.
Fields§
§id: StringThe subject (sub) — the stable user identifier.
name: StringDisplay name (name claim), empty when the token has none.
email: StringEmail address (email claim), empty when the token has none.
tenant_id: StringTenant identifier (tenant_id / tenant).
The empty string means “no tenant claim” — tokens from single-tenant
apps and tokens without the claim leave it empty. Use
IdentityUser::tenant when the difference between “no tenant claim”
and “declared empty” matters, or IdentityUser::require_tenant to
reject a principal without a tenant.
roles: Vec<String>Roles assigned to the user.
permissions: Vec<String>Fine-grained permissions assigned to the user.
Implementations§
Source§impl IdentityUser
impl IdentityUser
Sourcepub fn from_claims(claims: &dyn IClaims) -> Self
pub fn from_claims(claims: &dyn IClaims) -> Self
Build the identity from an authenticated principal.
Absent name / email / tenant_id claims become empty strings, so an
empty IdentityUser::tenant_id means “the principal carries no tenant
claim” rather than a tenant literally named "".
Sourcepub fn tenant(&self) -> Option<&str>
pub fn tenant(&self) -> Option<&str>
The tenant identifier, or None when the principal carries no tenant
claim.
IdentityUser::tenant_id stores “no claim” as the empty string for
backwards compatibility; this accessor makes that distinction explicit.
Sourcepub fn require_tenant(&self) -> Result<&str>
pub fn require_tenant(&self) -> Result<&str>
The tenant identifier, or Error::Forbidden when the principal carries
no tenant claim.
A missing tenant is not an authentication failure — the principal already proved who it is — it is a scope problem: the token simply does not reach any tenant. Reporting 403 instead of 401 keeps clients from retrying with the same valid credentials.
Sourcepub fn is_in_role(&self, role: &str) -> bool
pub fn is_in_role(&self, role: &str) -> bool
Whether the user has role.
Boolean check only — for a 401/403 decision use
RequestUser::require_role instead.
Sourcepub fn has_permission(&self, permission: &str) -> bool
pub fn has_permission(&self, permission: &str) -> bool
Whether the user has permission.
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
The display name, falling back to the identifier.