Misconfigured OAuth2LoginAuthenticationFilter when combining OAuth2 login and OAuth2 client configuration #16105
Labels
in: oauth2
An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
type: bug
A general bug
Milestone
Describe the bug
When configuring the SecurityFilterChain with both oAuth2Login and oAuth2Client sections, the resulting OAuth2LoginAuthenticationFilter is configured with the ClientRegistrationRepository and the OAuth2AuthorizedClientRepository specified in the oAuth2Client section instead of the corresponding instances in the oAuth2Login section.
The same seems to apply to other configured filters.
To Reproduce
Configure a SecurityFilterChain bean with oAuth2Login providing a custom ClientRegistrationRepository and OAuth2AuthorizedClientRepository. The correct beans are injected in the OAuth2LoginAuthenticationFilter on creation.
Then add the oAuth2Client section with different beans for ClientRegistrationRepository and OAuth2AuthorizedClientRepository.
Now OAuth2LoginAuthenticationFilter is constructed with the beans from the oAuth2Client section despite other instances being provided in the oAuth2Login section.
Expected behavior
The ClientRegistrationRepository and OAuth2AuthorizedClientRepository in the oAuth2Login section should always take precedent when constructing the OAuth2LoginAuthenticationFilter even when different instances are provided in the oAuth2Client section.
This is important for use cases where some ClientRegistrations are dedicated to login and others for authorizing use of a web API.
Sample
https://github.com/BWohlbrecht/spring-security-oauth2-sample
The text was updated successfully, but these errors were encountered: