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.
Option<IdentityUser> makes the endpoint work for anonymous callers too.
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), empty for single-tenant apps.
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) -> IdentityUser
pub fn from_claims(claims: &dyn IClaims) -> IdentityUser
Build the identity from an authenticated principal.
Sourcepub fn is_in_role(&self, role: &str) -> bool
pub fn is_in_role(&self, role: &str) -> bool
Whether the user has role.
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.
Trait Implementations§
Source§impl Clone for IdentityUser
impl Clone for IdentityUser
Source§fn clone(&self) -> IdentityUser
fn clone(&self) -> IdentityUser
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IdentityUser
impl Debug for IdentityUser
Source§impl Default for IdentityUser
impl Default for IdentityUser
Source§fn default() -> IdentityUser
fn default() -> IdentityUser
Source§impl<'de> Deserialize<'de> for IdentityUser
impl<'de> Deserialize<'de> for IdentityUser
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<IdentityUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<IdentityUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for IdentityUser
Source§impl PartialEq for IdentityUser
impl PartialEq for IdentityUser
Source§impl Serialize for IdentityUser
impl Serialize for IdentityUser
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for IdentityUser
Auto Trait Implementations§
impl Forget for IdentityUser
impl Freeze for IdentityUser
impl RefUnwindSafe for IdentityUser
impl Send for IdentityUser
impl Sync for IdentityUser
impl Unpin for IdentityUser
impl UnsafeUnpin for IdentityUser
impl UnwindSafe for IdentityUser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.