Skip to content

Add RestTemplate overloads to ClientRegistrations methods#19011

Closed
vpelikh wants to merge 1 commit intospring-projects:mainfrom
vpelikh:GH-16833
Closed

Add RestTemplate overloads to ClientRegistrations methods#19011
vpelikh wants to merge 1 commit intospring-projects:mainfrom
vpelikh:GH-16833

Conversation

@vpelikh
Copy link
Copy Markdown

@vpelikh vpelikh commented Mar 31, 2026

This PR introduces overloaded methods in ClientRegistrations that accept a custom RestTemplate:

  • fromOidcIssuerLocation(RestTemplate restTemplate, String issuer)
  • fromIssuerLocation(RestTemplate restTemplate, String issuer)

Fixes #16833 #16920

Motivation

Currently, the discovery endpoints (OIDC and OAuth2) are called using a static RestTemplate with fixed connection/read timeouts. This limits customization for users who need to:

  • Configure a proxy
  • Set custom timeouts
  • Add interceptors (e.g., for logging or authentication)
  • Use a different HTTP client (e.g., with mutual TLS)

By providing overloads that accept a RestTemplate, users can now inject their own configured instance while reusing the existing discovery logic.

Changes

  • Added two new public static methods as described above.
  • The existing methods (fromOidcIssuerLocation(String) and fromIssuerLocation(String)) delegate to the new overloads using the default static RestTemplate.
  • Internal oidc(...), oidcRfc8414(...), oauth(...) and getRfc8414Builder(...) methods were updated to accept a RestTemplate parameter; the existing static supplier-based approach remains unchanged.
  • Added comprehensive tests for the new overloads, verifying:
    • Success scenarios (OIDC, OAuth2, and fallback flows)
    • Null RestTemplate or empty issuer handling
    • Error cases with proper exception propagation

Impact

  • Backward compatible: existing callers are unaffected.
  • Users can now leverage their own RestTemplate for discovery requests.

Testing

  • All existing tests pass.
  • New tests cover the added methods, using MockWebServer to simulate various discovery endpoints and responses.

Please review and let me know if any additional changes are needed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 31, 2026
Signed-off-by: Vasily Pelikh <2010720+vpelikh@users.noreply.github.com>
@vpelikh
Copy link
Copy Markdown
Author

vpelikh commented Apr 1, 2026

Hey @jgrandja! Can you check this one?

@jgrandja
Copy link
Copy Markdown
Contributor

jgrandja commented Apr 1, 2026

@vpelikh We do not want to expose RestTemplate in the API.

Please see this comment as we plan to address this in the 7.2 release cycle.

@jgrandja jgrandja closed this Apr 1, 2026
@jgrandja jgrandja self-assigned this Apr 1, 2026
@jgrandja jgrandja added type: enhancement A general enhancement status: declined A suggestion or change that we don't feel we should currently apply in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adjust ClientRegistrations to allow to inject own instance of RestTemplate, ideally to use RestClient instead of ResTemplate

3 participants