Added ClientHttpRequestInterceptor implementation for RestClient, WebClient or RestTemplate requests with externally provided Bearer token like with BasicAuthenticationInterceptor:
@Configuration
public class RestClientConfiguration {
@Value("${example.token}")
private String token;
@Bean
public RestClient restClient() {
return RestClient.builder()
.baseUrl("https://api.example.com")
.requestInterceptor(new BearerAuthenticationInterceptor(() -> token))
.build();
}
}
Comment From: bclozel
Thanks for the proposal but we think that bearer token support is better suited in Spring Security with the OAuth2 support. If you're using another authentication mechanism that uses bearer token, creating your own interceptor is simple enough not to rely on a Framework provided one.
I'm closing this issue as a result.
See https://docs.spring.io/spring-security/reference/servlet/oauth2/index.html#oauth2-client