Skip to content

fix(oauth2): increase JWK retrieval timeout for slow connections#32286

Open
buildingvibes wants to merge 2 commits intojhipster:mainfrom
buildingvibes:fix/oidc-jwk-timeout
Open

fix(oauth2): increase JWK retrieval timeout for slow connections#32286
buildingvibes wants to merge 2 commits intojhipster:mainfrom
buildingvibes:fix/oidc-jwk-timeout

Conversation

@buildingvibes
Copy link

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) with NimbusJwtDecoder.withIssuerLocation(issuerUri).restOperations(restTemplate).build() in the imperative configuration
  • ReactiveJwtDecoders.fromOidcIssuerLocation(issuerUri) with NimbusReactiveJwtDecoder.withIssuerLocation(issuerUri).webClient(webClient).build() in the reactive microservice configuration

Both 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: Use NimbusJwtDecoder.withIssuerLocation() builder with a RestOperations configured via RestTemplateBuilder with 10s connect/read timeouts. The RestTemplateBuilder is now injected for all OAuth2 apps (previously only non-microservice).
  • SecurityConfiguration_reactive.java.ejs: Use NimbusReactiveJwtDecoder.withIssuerLocation() builder with a WebClient backed by Reactor Netty HttpClient configured with 10s connect/response timeouts (microservice case).

Test plan

  • Generated OAuth2 imperative monolith app compiles and starts correctly with Keycloak
  • Generated OAuth2 reactive microservice app compiles and starts correctly
  • Existing OAuth2 integration tests pass (TestSecurityConfiguration mocks JwtDecoder)
  • Verified using Spring Security 6.1+ withIssuerLocation() builder API

  • Checking this box is mandatory (this is just to show you read everything)

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On a slow internet connection, Okta/Auth0 JWK retrieval API fails with socket timeout

1 participant