Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the cached JWK Set expires while the JWKS endpoint is unreachable,
PyJWKClientraisesPyJWKClientConnectionErrorand every token verification fails until the endpoint recovers, even though the keys fetched a few minutes earlier are almost certainly still valid.This adds an opt-in
stale_if_errorparameter, named after RFC 5861. When refreshing an expired JWK Set fails, the client keeps serving the expired set for up to that many seconds past expiry instead of raising.Behaviour
OSError,http.client.HTTPException) and HTTP 500/502/503/504. Other HTTP errors and invalid payloads still raise.float("inf")serves stale for as long as fetching fails. NaN and negative values are rejected, as is a non-zero value withcache_jwk_set=False.get_jwk_set(refresh=True)never falls back, so an unknownkidduring an outage still reports the connection error.cooldown_durationseconds. This reusescooldown_durationrather than adding a parameter.cooldown_duration=0disables it, andget_jwk_set(refresh=True)always fetches.JWKSetCache.get()andis_expired()take amax_staleargument to support this.Security: during an outage, a key removed from the endpoint stays usable for up to
lifespan + stale_if_error. Removal already takes up tolifespanto apply today (and withcache_keys=Trueit never does). The default of0keeps current behaviour, so the reliability vs. revocation trade-off is the user's choice.Notes
stale_if_erroralone, I can drop them and open the backoff separately.kidstill triggers a fetch during backoff, since it may indicate key rotation.OSErrormatches the wrapping it adds, so the two PRs work in either merge order.