pub struct TokenClaims {
pub subject: String,
pub roles: Vec<String>,
pub permissions: Vec<String>,
pub extra: BTreeMap<String, String>,
pub expires_in: Option<Duration>,
}Expand description
Claims a caller hands to an ITokenIssuer.
Values are deliberately plain (String / Vec<String>) so the issuer does
not need to know the application’s claim structs. Anything that is not a
first-class field — tenant_id, name, email, custom scopes — goes into
TokenClaims::extra and is embedded verbatim.
Fields§
§subject: StringSubject (sub) — the stable user identifier. Required.
roles: Vec<String>Roles to embed (roles claim).
permissions: Vec<String>Fine-grained permissions to embed (permissions claim).
extra: BTreeMap<String, String>Additional string claims, embedded verbatim (e.g. tenant_id).
The issuer owns sub / jti / exp / iat: a key collision in extra
must not be able to override those.
expires_in: Option<Duration>Requested lifetime. None means the issuer’s configured default.
Implementations§
Source§impl TokenClaims
impl TokenClaims
Sourcepub fn new(subject: impl Into<String>) -> TokenClaims
pub fn new(subject: impl Into<String>) -> TokenClaims
Claims for subject with no roles, permissions or extra claims.
Sourcepub fn with_roles<I, S>(self, roles: I) -> TokenClaims
pub fn with_roles<I, S>(self, roles: I) -> TokenClaims
Set the roles claim.
Sourcepub fn with_permissions<I, S>(self, permissions: I) -> TokenClaims
pub fn with_permissions<I, S>(self, permissions: I) -> TokenClaims
Set the permissions claim.
Sourcepub fn with_claim(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> TokenClaims
pub fn with_claim( self, key: impl Into<String>, value: impl Into<String>, ) -> TokenClaims
Add one extra string claim.
Sourcepub fn expires_in(self, lifetime: Duration) -> TokenClaims
pub fn expires_in(self, lifetime: Duration) -> TokenClaims
Override the issuer’s default lifetime.
Trait Implementations§
Source§impl Clone for TokenClaims
impl Clone for TokenClaims
Source§fn clone(&self) -> TokenClaims
fn clone(&self) -> TokenClaims
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 TokenClaims
impl Debug for TokenClaims
Source§impl Default for TokenClaims
impl Default for TokenClaims
Source§fn default() -> TokenClaims
fn default() -> TokenClaims
impl Eq for TokenClaims
Source§impl PartialEq for TokenClaims
impl PartialEq for TokenClaims
impl StructuralPartialEq for TokenClaims
Auto Trait Implementations§
impl Forget for TokenClaims
impl Freeze for TokenClaims
impl Move for TokenClaims
impl RefUnwindSafe for TokenClaims
impl Send for TokenClaims
impl Sync for TokenClaims
impl Unpin for TokenClaims
impl UnsafeUnpin for TokenClaims
impl UnwindSafe for TokenClaims
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,
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.