You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Enahncement reuqest] [spring-boot-starter-oauth2-client] ability to provide custom RestClient instead of using RestTemplate for provider get token observablity
#16389
Open
patpatpat123 opened this issue
Jan 9, 2025
· 0 comments
How has this issue affected you?
Without this enhancement request, we are blind in production for issues getting the token using spring-boot-starter-oauth2-client
What are you trying to accomplish?
Observability for the call to get the token
What other alternatives have you considered?
Are you aware of any workarounds?
Dropping spring-boot-starter-oauth2-client in favor of writing our own two calls with the RestClient, which we would like to avoid (we like spring-boot-starter-oauth2-client)
Current Behavior
Here is our code:
@Configuration
public class RestClientConfig {
@Bean
public RestClient restClient(OAuth2AuthorizedClientManager authorizedClientManager, RestClient.Builder restClientBuilder) {
OAuth2ClientHttpRequestInterceptor interceptor = new OAuth2ClientHttpRequestInterceptor(authorizedClientManager);
return restClientBuilder
.requestInterceptor(interceptor)
.build();
}
@RestController
public class LessonsController {
private final RestClient restClient;
public LessonsController(RestClient restClient) {
this.restClient = restClient;
}
@GetMapping("/lessons")
public String fetchLessons() {
return restClient.get()
.uri("https://someprotectedresourceneedingtoken")
.attributes(clientRegistrationId("my-client"))
.retrieve()
.body(String.class);
}
}
Unfortunately, the first call to get the token is missing. We can only see the call to get the protected resource.
This is a drawback, the service providing the token is sometimes flaky. Overall, it is a fair requirement to have observability on the call to get the token as well.
Expected Behavior
We are hoping to see something like this:
This is achievable by not using spring-boot-starter-oauth2-client and writing our own code:
@GetMapping("/lessons")
public String fetchLessons() {
Map ssa = restClient.post()
.uri("https://service.com/token?scope=resolve+download&grant_type=client_credentials")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.headers(httpHeaders -> httpHeaders.setBasicAuth("aaa", "bbb"))
.retrieve()
.body(Map.class);
final MultiValueMap<String, String> params2 = new LinkedMultiValueMap<>();
params2.add("Authorization", "Bearer " + ssa.get("access_token"));
Consumer<HttpHeaders> consumer2 = it -> it.addAll(params2);
String result = restClient.get()
.uri("https://protectedresource...")
.headers(consumer2)
.retrieve()
.body(String.class);
return result;
}
But we like spring-boot-starter-oauth2-client and would like to avoid this route.
Would it be possible to enhance spring-boot-starter-oauth2-client, allowing it to pass in the custom RestClient? (not RestTemplate, not WebClient)
Rationale:
Many users already have a custom RestClient in their class path. It is properly configured with observability, SSL certificate, and so on.
Instead of defaulting the call to get the token with RestTemplate (which does not show any observability), it would be great if the user could pass the existing restClient.
Thank you for your time
The text was updated successfully, but these errors were encountered:
Context
How has this issue affected you?
Without this enhancement request, we are blind in production for issues getting the token using spring-boot-starter-oauth2-client
What are you trying to accomplish?
Observability for the call to get the token
What other alternatives have you considered?
Are you aware of any workarounds?
Dropping spring-boot-starter-oauth2-client in favor of writing our own two calls with the RestClient, which we would like to avoid (we like spring-boot-starter-oauth2-client)
Current Behavior
Here is our code:
With this code, we would get the following observation. (the get part is important)
Unfortunately, the first call to get the token is missing. We can only see the call to get the protected resource.
This is a drawback, the service providing the token is sometimes flaky. Overall, it is a fair requirement to have observability on the call to get the token as well.
Expected Behavior
We are hoping to see something like this:
This is achievable by not using spring-boot-starter-oauth2-client and writing our own code:
But we like spring-boot-starter-oauth2-client and would like to avoid this route.
Would it be possible to enhance spring-boot-starter-oauth2-client, allowing it to pass in the custom RestClient? (not RestTemplate, not WebClient)
Rationale:
Many users already have a custom RestClient in their class path. It is properly configured with observability, SSL certificate, and so on.
Instead of defaulting the call to get the token with RestTemplate (which does not show any observability), it would be great if the user could pass the existing restClient.
Thank you for your time
The text was updated successfully, but these errors were encountered: