pub struct AuthIdentity {
pub subject: String,
pub roles: Vec<String>,
pub claims: BTreeMap<String, Value>,
}Expand description
Authentication Identity
Represents an authenticated user’s identity within the NestForge framework. Contains the subject (typically user ID), roles, and additional custom claims.
§Fields
subject: The unique identifier for the user (e.g., user ID, email)roles: List of role names the user possessesclaims: Additional key-value pairs for custom authentication data
§Usage
This type is automatically populated by the framework’s authentication
middleware and can be accessed in handlers via the AuthUser extractor.
Fields§
§subject: String§roles: Vec<String>§claims: BTreeMap<String, Value>Implementations§
Source§impl AuthIdentity
impl AuthIdentity
Sourcepub fn with_roles<I, S>(self, roles: I) -> Self
pub fn with_roles<I, S>(self, roles: I) -> Self
Sourcepub fn with_claim(self, key: impl Into<String>, value: Value) -> Self
pub fn with_claim(self, key: impl Into<String>, value: Value) -> Self
Adds a custom claim to the authentication identity.
§Arguments
key: The claim keyvalue: The claim value
Sourcepub fn has_role(&self, role: &str) -> bool
pub fn has_role(&self, role: &str) -> bool
Checks if the identity has a specific role.
§Arguments
role: The role name to check
Returns true if the role is present in the identity’s roles.
Sourcepub fn require_role(&self, role: &str) -> Result<(), HttpException>
pub fn require_role(&self, role: &str) -> Result<(), HttpException>
Requires a specific role, returning an error if not present.
§Arguments
role: The required role name
Returns Ok if the role is present, or a forbidden HttpException if not.
Trait Implementations§
Source§impl Clone for AuthIdentity
impl Clone for AuthIdentity
Source§fn clone(&self) -> AuthIdentity
fn clone(&self) -> AuthIdentity
Returns a duplicate of the value. Read more
1.0.0 · 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 AuthIdentity
impl Debug for AuthIdentity
Source§impl Default for AuthIdentity
impl Default for AuthIdentity
Source§fn default() -> AuthIdentity
fn default() -> AuthIdentity
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for AuthIdentity
impl<'de> Deserialize<'de> for AuthIdentity
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 AuthIdentity
impl RefUnwindSafe for AuthIdentity
impl Send for AuthIdentity
impl Sync for AuthIdentity
impl Unpin for AuthIdentity
impl UnsafeUnpin for AuthIdentity
impl UnwindSafe for AuthIdentity
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