Skip to content

OAuth2ClientProperties not available when using a custom ClientRegistrationRepository #45685

@jharnack1

Description

@jharnack1

Not 100% sure if this is a bug or intended behaviour, so please close if it's not a bug.

In Spring Boot 3.4.x this would work:

@Bean
@ConditionalOnMissingBean({ClientRegistrationRepository.class})
InMemoryClientRegistrationRepository clientRegistrationRepository(
    OAuth2ClientProperties properties) {

    List<ClientRegistration> registrations = new OAuth2ClientPropertiesMapper(properties).asClientRegistrations().values().stream().toList();
    return new InMemoryClientRegistrationRepository(registrations);
}

(the actual use case is the workaround described in spring-projects/spring-security#7695 (comment))

With Spring Boot 3.5.0 I get this error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method clientRegistrationRepository in xxx.ClientRegistrationConfig required a bean of type 'org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties' in your configuration.

I need to add @EnableConfigurationProperties({OAuth2ClientProperties.class}) in my app for this to still work. I think in spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientConfigurations.java the OAuth2ClientProperties are only created when there is no custom ClientRegistrationRepository

I would expect OAuth2ClientProperties to exist if they are configured in application.yaml, even when I create a custom client registration repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions