fix(oauth2): increase JWK retrieval timeout for slow connections#32286
Open
buildingvibes wants to merge 2 commits intojhipster:mainfrom
Open
fix(oauth2): increase JWK retrieval timeout for slow connections#32286buildingvibes wants to merge 2 commits intojhipster:mainfrom
buildingvibes wants to merge 2 commits intojhipster:mainfrom
Conversation
…ow connections Replace JwtDecoders.fromOidcIssuerLocation() and ReactiveJwtDecoders.fromOidcIssuerLocation() with NimbusJwtDecoder.withIssuerLocation() and NimbusReactiveJwtDecoder.withIssuerLocation() respectively, using custom RestOperations/WebClient with 10-second connect and read timeouts. The default timeout of ~500ms causes startup failures for applications connecting to Okta/Auth0 endpoints on slower network connections. Closes jhipster#17550
setConnectTimeout/setReadTimeout were deprecated in Spring Boot 3.2 and removed in 3.5+. Use connectTimeout/readTimeout instead.
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.
Fixes #17550
Summary
On slow internet connections (especially from regions distant to Okta/Auth0 servers), the default ~500ms timeout for OIDC JWK retrieval causes application startup failures with
SocketTimeoutException: Read timed out.This PR replaces:
JwtDecoders.fromOidcIssuerLocation(issuerUri)withNimbusJwtDecoder.withIssuerLocation(issuerUri).restOperations(restTemplate).build()in the imperative configurationReactiveJwtDecoders.fromOidcIssuerLocation(issuerUri)withNimbusReactiveJwtDecoder.withIssuerLocation(issuerUri).webClient(webClient).build()in the reactive microservice configurationBoth use custom HTTP clients configured with 10-second connect and read timeouts, providing sufficient time for JWK set retrieval on slower networks while still failing promptly when the provider is unreachable.
Changes
SecurityConfiguration_imperative.java.ejs: UseNimbusJwtDecoder.withIssuerLocation()builder with aRestOperationsconfigured viaRestTemplateBuilderwith 10s connect/read timeouts. TheRestTemplateBuilderis now injected for all OAuth2 apps (previously only non-microservice).SecurityConfiguration_reactive.java.ejs: UseNimbusReactiveJwtDecoder.withIssuerLocation()builder with aWebClientbacked by Reactor NettyHttpClientconfigured with 10s connect/response timeouts (microservice case).Test plan
withIssuerLocation()builder API