Skip to content

Fetch discovered JWKS by kid so it can be cached - #219

Open
andrewfader wants to merge 1 commit into
omniauth:masterfrom
andrewfader:cache-jwks-by-kid
Open

andrewfader wants to merge 1 commit into
omniauth:masterfrom
andrewfader:cache-jwks-by-kid

Conversation

@andrewfader

@andrewfader andrewfader commented Oct 23, 2026 •

Copy link
Copy Markdown

With discovery: true, decode_id_token uses config.jwks, which fetches the JWKS on every callback and has no cache.

This looks the key up by kid through JSON::JWK::Set::Fetcher, the same path OpenIDConnect::ResponseObject::IdToken.decode takes with a discovery config. Setting JSON::JWK::Set::Fetcher.cache (e.g. Rails.cache) then caches the JWKS, and since the cache key includes the kid, a rotated key is fetched again instead of failing. Tokens without a kid and non-discovery setups are unchanged. Note the fetch for this path goes through JSON::JWK::Set::Fetcher.http_client rather than OpenIDConnect.http_client.

Tests: a discovery callback run twice fetches the JWKS once (fails before this change, 2 requests), and a callback signed with a newly rotated key succeeds.

Based on #124 by @nov, on current master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant