pub struct UserContext {
pub subject: String,
pub principal: PrincipalKind,
pub email: Option<String>,
pub username: Option<String>,
pub roles: Vec<String>,
pub scopes: Vec<String>,
pub capabilities: Vec<String>,
pub api_key_id: Option<String>,
}Expand description
The authenticated caller, resolved once at the edge (gateway) and propagated to every service via signed headers. This is the single identity type shared across all services.
Fields§
§subject: StringCanonical, opaque principal id. For User this is the user’s UUID (as a string);
for ApiKey/Service it is the principal’s stable id. Use UserContext::user_id
when a typed UUID is required.
principal: PrincipalKind§email: Option<String>§username: Option<String>§roles: Vec<String>§scopes: Vec<String>§capabilities: Vec<String>Effective account capabilities (entitlements) resolved by the identity service.
api_key_id: Option<String>Present only for ApiKey principals.
Implementations§
Source§impl UserContext
impl UserContext
Sourcepub fn user_id(&self) -> Result<Uuid, AppError>
pub fn user_id(&self) -> Result<Uuid, AppError>
Parse the subject as a user UUID. Errors for non-UUID principals (e.g. API keys).
Sourcepub fn user_id_opt(&self) -> Option<Uuid>
pub fn user_id_opt(&self) -> Option<Uuid>
Parse the subject as a user UUID, or None for non-UUID principals.
pub fn is_user(&self) -> bool
pub fn is_api_key(&self) -> bool
pub fn is_service(&self) -> bool
pub fn has_role(&self, role: &str) -> bool
pub fn has_any_role(&self, roles: &[&str]) -> bool
pub fn require_role(&self, role: &str) -> Result<(), AppError>
pub fn require_any_role(&self, roles: &[&str]) -> Result<(), AppError>
Sourcepub fn is_admin(&self) -> bool
pub fn is_admin(&self) -> bool
Platform-admin check: holds ADMIN or any *_ADMIN role (case-insensitive).
pub fn require_admin(&self) -> Result<(), AppError>
pub fn has_scope(&self, scope: &str) -> bool
pub fn require_scope(&self, scope: &str) -> Result<(), AppError>
pub fn has_capability(&self, capability: &str) -> bool
pub fn require_capability(&self, capability: &str) -> Result<(), AppError>
Trait Implementations§
Source§impl Clone for UserContext
impl Clone for UserContext
Source§fn clone(&self) -> UserContext
fn clone(&self) -> UserContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UserContext
impl Debug for UserContext
Source§impl<'de> Deserialize<'de> for UserContext
impl<'de> Deserialize<'de> for UserContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for UserContext
impl RefUnwindSafe for UserContext
impl Send for UserContext
impl Sync for UserContext
impl Unpin for UserContext
impl UnsafeUnpin for UserContext
impl UnwindSafe for UserContext
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
Mutably borrows from an owned value. Read more