🔑 oidc: a scheduled key fetch no longer delays the refetch for a newly rotated key
Browse files at this commit9ffa9cd4e4cbeeb36b92c9955daff074ba03ca0aParent: a05110d1 changed file +9 -2
crates/in-web/src/oidc.rsmodified+9 -2
| @@ -590,7 +590,7 @@ struct Cache { | ||
| 590 | 590 | discovery_failed_at: Option<Instant>, |
| 591 | 591 | /// The key set and when it was fetched. |
| 592 | 592 | 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. | |
| 594 | 594 | keys_refresh_at: Option<Instant>, |
| 595 | 595 | /// The client-credentials token for `im`, and the instant it stops being used. |
| 596 | 596 | service: Option<(String, Instant)>, |
| @@ -773,9 +773,16 @@ impl OidcClient { | ||
| 773 | 773 | return answer; |
| 774 | 774 | } |
| 775 | 775 | 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 | + } | |
| 777 | 781 | let fetched = self.get_json::<Jwks>(&endpoints.jwks).await; |
| 778 | 782 | let mut cache = self.cache.lock().await; |
| 783 | + if fetched.is_err() { | |
| 784 | + cache.keys_refresh_at = Some(Instant::now()); | |
| 785 | + } | |
| 779 | 786 | match fetched { |
| 780 | 787 | Ok(jwks) => { |
| 781 | 788 | let keys = Arc::new(KeySet::from_jwks(&jwks)); |