pub struct AuthClaims {
pub sub: String,
pub roles: Vec<String>,
pub exp: u64,
pub iss: Option<String>,
pub aud: Option<String>,
}Expand description
Standard claims decoded from a JWT (Bearer or session cookie).
Include roles as a JSON array of strings in the token payload, for example:
{"sub":"user-1","roles":["admin","user"],"exp":...}.
Fields§
§sub: StringSubject (typically user id).
roles: Vec<String>Role names for crate::auth::RequireRole and AuthClaims::has_role.
exp: u64Expiration time (Unix seconds). Required for validation.
iss: Option<String>Issuer — include when validating with crate::auth::AuthConfig::with_issuer.
aud: Option<String>Audience — include when validating with crate::auth::AuthConfig::with_audience.
Implementations§
Source§impl AuthClaims
impl AuthClaims
Sourcepub fn new(sub: impl Into<String>, roles: Vec<String>, ttl_secs: u64) -> Self
pub fn new(sub: impl Into<String>, roles: Vec<String>, ttl_secs: u64) -> Self
Build claims with exp set to now + ttl_secs.
Sourcepub fn has_role(&self, role: &str) -> bool
pub fn has_role(&self, role: &str) -> bool
Returns true if role is present in Self::roles.
Sourcepub fn has_any_role(&self, roles: &[&str]) -> bool
pub fn has_any_role(&self, roles: &[&str]) -> bool
Returns true if the principal has any of the given roles.
Sourcepub fn has_all_roles(&self, roles: &[&str]) -> bool
pub fn has_all_roles(&self, roles: &[&str]) -> bool
Returns true if the principal has all of the given roles.
Trait Implementations§
Source§impl Clone for AuthClaims
impl Clone for AuthClaims
Source§fn clone(&self) -> AuthClaims
fn clone(&self) -> AuthClaims
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 AuthClaims
impl Debug for AuthClaims
Source§impl<'de> Deserialize<'de> for AuthClaims
impl<'de> Deserialize<'de> for AuthClaims
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 AuthClaims
impl RefUnwindSafe for AuthClaims
impl Send for AuthClaims
impl Sync for AuthClaims
impl Unpin for AuthClaims
impl UnsafeUnpin for AuthClaims
impl UnwindSafe for AuthClaims
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