Можно ли использовать аутентификацию Oauth2 с новым RestClient?JAVA

Программисты JAVA общаются здесь
Anonymous
Можно ли использовать аутентификацию Oauth2 с новым RestClient?

Сообщение Anonymous »

В WebClient я использую этот код, чтобы заставить веб-клиент работать с конечной точкой Spring Resource Server.
Можно ли заставить этот код работать с новым RestClient?
@Bean
UserClient userClient(OAuth2AuthorizedClientManager authorizedClientManager) {
ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2 =
new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
oauth2.setDefaultOAuth2AuthorizedClient(true);

WebClient webClient = WebClient.builder()
.baseUrl("http://127.0.0.1:8091")
.apply(oauth2.oauth2Configuration())
.build();
WebClientAdapter adapter = WebClientAdapter.create(webClient);
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
UserClient userClient = factory.createClient(UserClient.class);
return userClient;
}

@Bean
OAuth2AuthorizedClientManager authorizedClientManager(
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientRepository authorizedClientRepository) {

OAuth2AuthorizedClientProvider authorizedClientProvider =
OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials()
.authorizationCode()
.refreshToken()
.build();

DefaultOAuth2AuthorizedClientManager authorizedClientManager =
new DefaultOAuth2AuthorizedClientManager(
clientRegistrationRepository, authorizedClientRepository);

authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);

return authorizedClientManager;
}

Возможно ли решение, подобное приведенному ниже коду?
RestClient restClient = RestClient.builder()
.baseUrl("http://127.0.0.1:8091")
.apply( ??????? )
.build();

Вернуться в «JAVA»