This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Security 6.5.3!spring-doc.cn

HTTP Interface Integration

Spring Security’s OAuth Support can integrate with RestClient and WebClient HTTP Interface based REST Clients.spring-doc.cn

Configuration

After RestClient or WebClient specific configuration, usage of HTTP Interface Integration only requires adding a @ClientRegistrationId to methods that require OAuth.spring-doc.cn

Since the presence of @ClientRegistrationId determines if and how the OAuth token will be resolved, it is safe to add Spring Security’s OAuth support any configuration.spring-doc.cn

RestClient Configuration

Spring Security’s OAuth Support can integrate with HTTP Interface based REST Clients backed by RestClient. The first step is to create an OAuthAuthorizedClientManager Bean.spring-doc.cn

Next you must configure HttpServiceProxyFactory and RestClient to be aware of @ClientRegistrationId To simplify this configuration, use OAuth2RestClientHttpServiceGroupConfigurer.spring-doc.cn

@Bean
OAuth2RestClientHttpServiceGroupConfigurer securityConfigurer(
		OAuth2AuthorizedClientManager manager) {
	return OAuth2RestClientHttpServiceGroupConfigurer.from(manager);
}
@Bean
fun securityConfigurer(manager: OAuth2AuthorizedClientManager): OAuth2RestClientHttpServiceGroupConfigurer {
    return OAuth2RestClientHttpServiceGroupConfigurer.from(manager)
}

The configuration:spring-doc.cn

WebClient Configuration

Spring Security’s OAuth Support can integrate with HTTP Interface based REST Clients backed by WebClient. The first step is to create an ReactiveOAuthAuthorizedClientManager Bean.spring-doc.cn

Next you must configure HttpServiceProxyFactory and WebRestClient to be aware of @ClientRegistrationId To simplify this configuration, use OAuth2WebClientHttpServiceGroupConfigurer.spring-doc.cn

@Bean
OAuth2WebClientHttpServiceGroupConfigurer securityConfigurer(
		ReactiveOAuth2AuthorizedClientManager manager) {
	return OAuth2WebClientHttpServiceGroupConfigurer.from(manager);
}
@Bean
fun securityConfigurer(
    manager: ReactiveOAuth2AuthorizedClientManager?
): OAuth2WebClientHttpServiceGroupConfigurer {
    return OAuth2WebClientHttpServiceGroupConfigurer.from(manager)
}

The configuration:spring-doc.cn

@ClientRegistrationId

You can add the ClientRegistrationId on the HTTP Interface to specify which ClientRegistration to use.spring-doc.cn

	@GetExchange("/user")
	@ClientRegistrationId("github")
	User getAuthenticatedUser();
    @GetExchange("/user")
    @ClientRegistrationId("github")
    fun getAuthenticatedUser() : User

ClientRegistrationIdProcessor