pub struct TokenClaims { /* private fields */ }Expand description
What an adapter established about a presented token, before this crate’s own rules ran.
“Established” means the adapter verified the signature (JWT) or asked the
authorization server (introspection). It is deliberately not a type that can
be built from a raw string in this crate: there is no path from an
Authorization header to a TokenClaims that skips the adapter, because
that is the property that keeps a decode from becoming a verify.
Implementations§
Source§impl TokenClaims
impl TokenClaims
Sourcepub fn with_subject(self, subject: impl Into<Arc<str>>) -> Self
pub fn with_subject(self, subject: impl Into<Arc<str>>) -> Self
Sets the subject — who the token is about.
Sourcepub fn with_issuer(self, issuer: impl Into<Arc<str>>) -> Self
pub fn with_issuer(self, issuer: impl Into<Arc<str>>) -> Self
Sets the issuer that minted the token.
Sourcepub fn with_audience(self, audience: ResourceUri) -> Self
pub fn with_audience(self, audience: ResourceUri) -> Self
Adds an audience entry.
A builder rather than a setter because RFC 7519 §4.1.3 allows aud to
be either a single string or an array, and both have to land in the same
place.
Sourcepub fn with_audience_string(self, audience: impl AsRef<str>) -> Self
pub fn with_audience_string(self, audience: impl AsRef<str>) -> Self
Adds an audience entry that arrives as a string.
Skipped rather than fatal when it does not parse. An aud entry that is
not an absolute URI cannot equal this server’s resource, so ignoring it
and letting the audience check decide is the same answer as refusing —
and a server that names one malformed audience alongside a valid one
has still issued a usable token, which refusing outright would throw
away.
Sourcepub const fn with_expiry(self, at: SystemTime) -> Self
pub const fn with_expiry(self, at: SystemTime) -> Self
Sets when the token stops being valid.
Sourcepub const fn with_not_before(self, at: SystemTime) -> Self
pub const fn with_not_before(self, at: SystemTime) -> Self
Sets when the token starts being valid.
Sourcepub fn with_scope(self, scope: impl Into<Arc<str>>) -> Self
pub fn with_scope(self, scope: impl Into<Arc<str>>) -> Self
Declares a scope the token carries.
Sourcepub fn audience(&self) -> &[ResourceUri]
pub fn audience(&self) -> &[ResourceUri]
Every audience entry, already canonicalised.
Sourcepub fn is_audience(&self, resource: &ResourceUri) -> bool
pub fn is_audience(&self, resource: &ResourceUri) -> bool
Whether the token is bound to resource.
Exact equality against a canonicalised ResourceUri, and equality
against any element of aud — which is what RFC 7519 §4.1.3 means by
an array audience. “Contains the resource” is the same predicate; what it
is not is “contains the resource’s host”, which is the check that would
let a sibling server’s token through.