pub struct JwtVerifier { /* private fields */ }Expand description
Verifies bearer tokens and maps their claims to an AuthPrincipal. Cheap to clone.
See the module documentation.
Implementations§
Source§impl JwtVerifier
impl JwtVerifier
Sourcepub fn new(keys: impl IntoIterator<Item = JwtKey>) -> Self
pub fn new(keys: impl IntoIterator<Item = JwtKey>) -> Self
A verifier over fixed keys.
Sourcepub fn jwks(jwks: JwksClient) -> Self
pub fn jwks(jwks: JwksClient) -> Self
A verifier over the key set jwks fetches (and refetches on an unknown kid).
Sourcepub fn issuer(self, issuer: impl Into<String>) -> Self
pub fn issuer(self, issuer: impl Into<String>) -> Self
Accept tokens whose iss is issuer (repeat for several). Once set, iss is required.
Sourcepub fn audience(self, audience: impl Into<String>) -> Self
pub fn audience(self, audience: impl Into<String>) -> Self
Accept tokens whose aud contains audience (repeat for several). Once set, aud is
required. Set it: without an audience a token minted for another service is accepted.
A verifier with neither an issuer nor an audience rejects every token (see
dangerous_any_issuer).
Sourcepub fn dangerous_any_issuer(self) -> Self
pub fn dangerous_any_issuer(self) -> Self
Accept tokens from any issuer even though no issuer is set. Records
DANGEROUS_ANY_ISSUER in the posture registry.
Dangerous. A verifier with neither an issuer nor an audience fails every verification
with AuthError::Config; calling both this and
dangerous_any_audience re-opens the 0.10.0 behaviour:
any token signed by a trusted key is accepted, whoever minted it and for whichever service.
Only for keys that sign tokens for this service alone (a test, a single-service secret).
Sourcepub fn any_issuer_dangerous(self) -> Self
👎Deprecated since 0.11.0: renamed to dangerous_any_issuer (ADR 0013 naming)
pub fn any_issuer_dangerous(self) -> Self
renamed to dangerous_any_issuer (ADR 0013 naming)
Accept tokens from any issuer.
Sourcepub fn dangerous_any_audience(self) -> Self
pub fn dangerous_any_audience(self) -> Self
Accept tokens for any audience even though no audience is set. Records
DANGEROUS_ANY_AUDIENCE in the posture registry.
Dangerous: see dangerous_any_issuer; a token minted for
another service of the same issuer is accepted.
Sourcepub fn any_audience_dangerous(self) -> Self
👎Deprecated since 0.11.0: renamed to dangerous_any_audience (ADR 0013 naming)
pub fn any_audience_dangerous(self) -> Self
renamed to dangerous_any_audience (ADR 0013 naming)
Accept tokens for any audience.
Sourcepub fn algorithms(self, algorithms: impl IntoIterator<Item = Algorithm>) -> Self
pub fn algorithms(self, algorithms: impl IntoIterator<Item = Algorithm>) -> Self
Only accept these algorithms (default: whatever the matching key’s family allows).
Sourcepub fn require_claim(self, claim: impl Into<String>) -> Self
pub fn require_claim(self, claim: impl Into<String>) -> Self
Reject tokens without the claim claim.
Sourcepub fn require_exp(self, require: bool) -> Self
pub fn require_exp(self, require: bool) -> Self
Whether exp must be present (default true). An exp that is present is always checked.
Sourcepub fn leeway(self, leeway: Duration) -> Self
pub fn leeway(self, leeway: Duration) -> Self
Clock-skew allowance for exp and nbf (default DEFAULT_LEEWAY).
Sourcepub fn claims(self, mapping: ClaimMapping) -> Self
pub fn claims(self, mapping: ClaimMapping) -> Self
Map claims to the principal with mapping.
Sourcepub fn with_clock(self, clock: WallClock) -> Self
pub fn with_clock(self, clock: WallClock) -> Self
Read the time from clock (an anchored clock follows a TestExecutor’s virtual time).
Sourcepub fn verify(&self, token: &str) -> Effect<AuthPrincipal, AuthError>
pub fn verify(&self, token: &str) -> Effect<AuthPrincipal, AuthError>
The principal token stands for, or why it is rejected: AuthError::Malformed (not a
JWT), AuthError::InvalidCredentials (signature, algorithm),
AuthError::UnknownKey, AuthError::Expired, AuthError::NotYetValid,
AuthError::InvalidClaims; AuthError::Unavailable when the JWKS cannot be fetched;
AuthError::Config when neither an issuer nor an audience is set, and
AuthError::Key for an HMAC secret that is too short.
Trait Implementations§
Source§impl Clone for JwtVerifier
impl Clone for JwtVerifier
Auto Trait Implementations§
impl !RefUnwindSafe for JwtVerifier
impl !UnwindSafe for JwtVerifier
impl Freeze for JwtVerifier
impl Send for JwtVerifier
impl Sync for JwtVerifier
impl Unpin for JwtVerifier
impl UnsafeUnpin for JwtVerifier
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<P> PolicyExt for P
impl<P> PolicyExt for P
Source§fn and<P>(self, other: P) -> And<Self, P>
fn and<P>(self, other: P) -> And<Self, P>
other runs only when self allows.Source§fn or<P>(self, other: P) -> Or<Self, P>
fn or<P>(self, other: P) -> Or<Self, P>
other runs only when self denies (its denial is kept).Source§fn negate(self, reason: impl Into<String>) -> Not<Self>
fn negate(self, reason: impl Into<String>) -> Not<Self>
self denies; denies with reason when it allows.Source§fn dangerous_cross_tenant(self, reason: impl Into<String>) -> CrossTenant<Self>
fn dangerous_cross_tenant(self, reason: impl Into<String>) -> CrossTenant<Self>
check_with / authorize_with, it decides on a Tenanted resource
for principals of any tenant. reason says who needs that (support tooling, a platform
operator) and is kept on the policy for review. Read more