forge
Explore
Log in

Don't you dare go Hollow

🔑 oidc: a scheduled key fetch no longer delays the refetch for a newly rotated key

Browse files at this commit

9ffa9cd4e4cbeeb36b92c9955daff074ba03ca0aAhmet Kaan GümüşParent: a05110d
crates/in-web/src/oidc.rsmodified+9 -2
@@ -590,7 +590,7 @@ struct Cache {
590590 discovery_failed_at: Option<Instant>,
591591 /// The key set and when it was fetched.
592592 keys: Option<(Instant, Arc<KeySet>)>,
593- /// When the keys were last fetched for an unknown `kid`. Limits those fetches.
593+ /// When the keys were last fetched for an unknown `kid`, or a fetch failed. Limits those fetches.
594594 keys_refresh_at: Option<Instant>,
595595 /// The client-credentials token for `im`, and the instant it stops being used.
596596 service: Option<(String, Instant)>,
@@ -773,9 +773,16 @@ impl OidcClient {
773773 return answer;
774774 }
775775 let endpoints = self.endpoints().await;
776- self.cache.lock().await.keys_refresh_at = Some(Instant::now());
776+ // Only a forced refetch or a failure starts the gap. A scheduled fetch does not, so the first token
777+ // signed by a newly rotated key is verified at once.
778+ if force {
779+ self.cache.lock().await.keys_refresh_at = Some(Instant::now());
780+ }
777781 let fetched = self.get_json::<Jwks>(&endpoints.jwks).await;
778782 let mut cache = self.cache.lock().await;
783+ if fetched.is_err() {
784+ cache.keys_refresh_at = Some(Instant::now());
785+ }
779786 match fetched {
780787 Ok(jwks) => {
781788 let keys = Arc::new(KeySet::from_jwks(&jwks));