spring-projects / spring-projects/spring-security
`RefreshTokenOAuth2AuthorizedClientProvider` initialization slows down application startup
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Describe the bug
During application startup RefreshTokenOAuth2AuthorizedClientProvider is created by org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration.OAuth2AuthorizedClientManagerRegistrar#getRefreshTokenAuthorizedClientProvider
and because of
it requires quite some time (300ms; ~3% of my application startup time is spent there) to initialize because it creates a HttpClient:
Currently it's not possible in any way to disable this behavior because
- There is no constructor of
RefreshTokenOAuth2AuthorizedClientProviderthat leavesaccessTokenResponseClientempty - The classes can't be overriden/proxied because they are all declared
final- I'm not sure why this is the case because
OAuth2AuthorizedClientManagerRegistrar#getAuthorizedClientProviderByTypechecks for subclasses of this type which is impossible when they have been declaredfinal
- I'm not sure why this is the case because
To Reproduce
N/A see code above
Expected behavior
- Create a constructor of
RefreshTokenOAuth2AuthorizedClientProviderthat does not initializeaccessTokenResponseClient - Make
RefreshTokenOAuth2AuthorizedClientProvidernot final so that users can provide their custom implementations. This should be done for all classes that implementOAuth2AuthorizedClientProvider - Maybe initialize the default
RestClientRefreshTokenTokenResponseClienton a background thread if available to not slow down the application start
Sample
Already described above
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with OAuth2ClientConfiguration.OAuth2AuthorizedClientManagerRegistrar#getRefreshTokenAuthorizedClientProvider and RefreshTokenOAuth2AuthorizedClientProvider.java at the linked initialization line. Trace which OAuth2AuthorizedClientProvider implementations and constructors are created during startup, then use the existing startup reproduction to verify that the chosen change avoids unnecessary initialization while preserving refresh-token behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- authentication, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100