-
Notifications
You must be signed in to change notification settings - Fork 6k
Add possibility to customize JwkSource of NimbusJwtDecoder #17046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
554e2cc
to
d3f0b27
Compare
Signed-off-by: Mark Bonnekessel <[email protected]>
Thanks for the PR, @marbon87! I'm curious if it would be easier to construct your own If so, this PR instead might add something similar to |
Hi @jzheaux, thanks for your feedback! If i unterstand the current implementation correctly, adding a separate builder-creation method like Furthermore i cannot use SpringJWKSource because it's private nor can i customize it because it's final. Overall I have to write a lot more code as a user of spring-security, if i want to increase the timeouts. |
Possibly, though I wonder if it is as much as you are thinking (perhaps it's also more than I'm thinking). As for the URI, I think that Nimbus has an API that's quite adept at this: AuthorizationServerMetadata metadata = AuthorizationServerMetadata
.resolve(new Issuer("https://example.org/issuer"));
String jwkSetUri = metadata.getJwkSetUri();
// ... It seems to me that this would result in the following: @Bean
JwtDecoder jwtDecoder(String issuer) {
AuthorizationServerMetadata metadata = AuthorizationServerMetadata
.resolve(new Issuer("https://example.org/issuer"));
String jwkSetUri = metadata.getJwkSetUri();
JWKSource<SecurityContext> source = JWKSourceBuilder.create(new URL(jwkSetUri))
// your caching settings
.build();
return NimbusJwtDecoder.withJwkSource(source)
// your decoding settings
.build();
} Alternatively, Spring Cache is also quite adept at timeouts and other caching functions if you are open to working with that instead. What complexities am I failing to consider? |
Your suggestion should work but i am not sure what's missing to get it "completed". Regarding to spring cache, i did not find an simple solutation for a refresh or/and fault tolerant ahead cache. |
Gotcha, I can see how the code gives that impression. It uses a custom If you want to look further into Spring Cache, I think Spring's JCache integration would make sense since you can integrate in this way with Hazelcast and other caches that support refresh-ahead. That said, you know your requirements best and whether the ease of Nimbus's in-memory caching will suit your needs.
Am I understanding correctly that you are asking for how the PR would change? To add |
Thanks for your offer, but i think i can manage that. Should i close this pr and create a new one referencing this? |
Up to you, @marbon87. Honestly, the title of the PR still seems to work well with what we are talking about now and I'd be fine with reusing it. |
We want to increase the cache-ttl of the NimbusJwtDecoder respectively the underlying JWKSource. Furthermore we want to use the refresh-ahead caching of JWKSource.
The com.nimbusds.jose.jwk.source.JWKSourceBuilder provides a lot of features to customize how jwks are cached / update etc. but currently there is no way to customize it.
The implemented possiiblity to customiz the used JWKSourceBuilder in NimbusJwtDecoder allows to use all features from JWKSourceBuilder.