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
impl Jwks
Sourcepub fn builder(
url: impl Into<String>,
fetch: impl Fetch + 'static,
) -> JwksBuilder
pub fn builder( url: impl Into<String>, fetch: impl Fetch + 'static, ) -> JwksBuilder
Start building one for url, fetched through fetch.
Sourcepub fn keys(&self) -> &JwtKeys
pub fn keys(&self) -> &JwtKeys
The keys in force, for crate::JwtConfig::keys.
Sourcepub fn status(&self) -> JwksStatus
pub fn status(&self) -> JwksStatus
What has happened so far.
Sourcepub fn next_refresh_in(&self) -> Duration
pub fn next_refresh_in(&self) -> Duration
How long until the next fetch is due.
Sourcepub async fn refresh(&self) -> Result<(), FetchError>
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.
Sourcepub async fn refresh_forever<S, F>(&self, sleep: S)
pub async fn refresh_forever<S, F>(&self, sleep: S)
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.
Sourcepub async fn ensure_for_token(&self, token: &str)
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).