Skip to main content

IClaims

Trait IClaims 

Source
pub trait IClaims: Send + Sync {
    // Required methods
    fn subject(&self) -> &str;
    fn roles(&self) -> &[String];
    fn permissions(&self) -> &[String];
    fn claims(&self) -> &HashMap<String, String>;
    fn clone_box(&self) -> Box<dyn IClaims>;

    // Provided methods
    fn has_role(&self, role: &str) -> bool { ... }
    fn get_userid(&self) -> &str { ... }
    fn get_username(&self) -> Option<&str> { ... }
    fn get_tenantid(&self) -> Option<&str> { ... }
}
Expand description

Claims extracted from an authentication token (JWT, etc.).

Stored in IHttpContext extensions via IClaimsExt.

Required Methods§

Source

fn subject(&self) -> &str

The user / subject identifier.

Source

fn roles(&self) -> &[String]

Roles assigned to the user.

Source

fn permissions(&self) -> &[String]

Permissions assigned to the user.

Source

fn claims(&self) -> &HashMap<String, String>

Raw claims map (key-value pairs from the token).

Source

fn clone_box(&self) -> Box<dyn IClaims>

Clone the claims into a new boxed trait object.

Provided Methods§

Source

fn has_role(&self, role: &str) -> bool

Check whether a specific role is assigned.

if claims.has_role("admin") { ... }
Source

fn get_userid(&self) -> &str

Alias for subject() — returns the user identifier.

Source

fn get_username(&self) -> Option<&str>

Read the display name from the raw claims map (key "name"). Returns None when absent.

Source

fn get_tenantid(&self) -> Option<&str>

Read the tenant identifier from the raw claims map (key "tenant_id"). Returns None when absent.

Trait Implementations§

Source§

impl Clone for Box<dyn IClaims>

Source§

fn clone(&self) -> Box<dyn IClaims>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§