Skip to main content

Jwks

Struct Jwks 

Source
pub struct Jwks { /* private fields */ }
Expand description

The keys at a JWKS URL, fetched and kept current. See the module documentation.

Cloning shares it. Jwks::keys is the handle a crate::JwtConfig verifies with; crate::JwtConfig::with_jwks sets both.

Implementations§

Source§

impl Jwks

Source

pub fn builder( url: impl Into<String>, fetch: impl Fetch + 'static, ) -> JwksBuilder

Start building one for url, fetched through fetch.

Source

pub fn keys(&self) -> &JwtKeys

The keys in force, for crate::JwtConfig::keys.

Source

pub fn url(&self) -> &str

The URL the keys are fetched from.

Source

pub fn is_loaded(&self) -> bool

Whether a set has ever been fetched.

Source

pub fn status(&self) -> JwksStatus

What has happened so far.

Source

pub fn next_refresh_in(&self) -> Duration

How long until the next fetch is due.

Source

pub async fn refresh(&self) -> Result<(), FetchError>

Fetch the set now, whenever it was last fetched, waiting for any fetch already in flight first. The outcome is also in Jwks::status.

Always from the provider, never from a JwksStore: this is what a schedule calls, and what writes the store for everyone else.

Source

pub async fn refresh_forever<S, F>(&self, sleep: S)
where S: FnMut(Duration) -> F, F: Future<Output = ()>,

Keep the set fresh until the end of time: fetch whenever the next fetch is due, sleeping with sleep in between.

For a host that runs background tasks – the server spawns this on its runtime with tokio::time::sleep. Once it runs, requests no longer refresh a set that is merely due; they still fetch for an unknown kid.

Source

pub async fn ensure_for_token(&self, token: &str)

Make sure the keys a token needs are here, fetching if they may not be. Never fails: a token still without a key is refused by the synchronous check that follows, as PGRST301.

Returns without awaiting anything when the set in force holds a key for the token’s header – unless no background task keeps the set fresh and it is due, when the request that notices fetches it (and one that finds a fetch already running goes on with the set it has).

Trait Implementations§

Source§

impl Clone for Jwks

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Jwks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Jwks

§

impl !UnwindSafe for Jwks

§

impl Freeze for Jwks

§

impl Send for Jwks

§

impl Sync for Jwks

§

impl Unpin for Jwks

§

impl UnsafeUnpin for Jwks

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more