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>) -> Self
pub fn new(subject: impl Into<String>) -> Self
Claims for subject with no roles, permissions or extra claims.
Sourcepub fn with_roles<I, S>(self, roles: I) -> Self
pub fn with_roles<I, S>(self, roles: I) -> Self
Set the roles claim.
Sourcepub fn with_permissions<I, S>(self, permissions: I) -> Self
pub fn with_permissions<I, S>(self, permissions: I) -> Self
Set the permissions claim.
Sourcepub fn with_claim(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_claim( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add one extra string claim.
Sourcepub fn expires_in(self, lifetime: Duration) -> Self
pub fn expires_in(self, lifetime: Duration) -> Self
Override the issuer’s default lifetime.