pub struct CurrentUser {
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.
Put it in a request with #[fromclaim] and the binder fills it from the
authenticated principal:
#[derive(WebxRequestMeta)]
pub struct CreateOrderRequest {
#[fromclaim]
pub user: CurrentUser,
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<CurrentUser> 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 CurrentUser
impl CurrentUser
Sourcepub fn from_claims(claims: &dyn IClaims) -> CurrentUser
pub fn from_claims(claims: &dyn IClaims) -> CurrentUser
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 CurrentUser
impl Clone for CurrentUser
Source§fn clone(&self) -> CurrentUser
fn clone(&self) -> CurrentUser
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 CurrentUser
impl Debug for CurrentUser
Source§impl Default for CurrentUser
impl Default for CurrentUser
Source§fn default() -> CurrentUser
fn default() -> CurrentUser
Source§impl<'de> Deserialize<'de> for CurrentUser
impl<'de> Deserialize<'de> for CurrentUser
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CurrentUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CurrentUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for CurrentUser
Source§impl PartialEq for CurrentUser
impl PartialEq for CurrentUser
Source§impl Serialize for CurrentUser
impl Serialize for CurrentUser
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 CurrentUser
Auto Trait Implementations§
impl Forget for CurrentUser
impl Freeze for CurrentUser
impl RefUnwindSafe for CurrentUser
impl Send for CurrentUser
impl Sync for CurrentUser
impl Unpin for CurrentUser
impl UnsafeUnpin for CurrentUser
impl UnwindSafe for CurrentUser
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.