-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enahncement request] [spring-boot-starter-oauth2-client] ability to provide custom RestClient instead of using RestTemplate for provider get token observablity #16389
Comments
Hello team, is it possible to get some help on this? |
Hi, @patpatpat123, as far as I know what you are asking for is already possible: https://docs.spring.io/spring-security/reference/servlet/oauth2/client/authorization-grants.html#oauth2-client-authorization-code-access-token Am I misunderstanding? |
Hello @jzheaux , Wanted to thank you for your time looking into this. I saw the guide. With either
or
or
I am still seeing the use of RestTemplate
I would have expected to see the use of the rest client instead of the rest template. I can see the setRestClient() method suggested by the doc is being called. But I would have expected the same RestClient provided, which has observability configured would get triggered. Also, just wanted to say, I think there is a typo in the doc (please see screenshot): ![]() Could you please help by letting me know if I did something wrong in my RestClientConfig class? Thank you again |
Hi @patpatpat123, thanks for reaching out. As @jzheaux mentioned, this is well supported through the example linked in the comment. The second configuration you provided is correct, the others are not. I have double-checked that this configuration works. At this point, I am not able to reproduce your finding. Could you please provide a minimal, reproducible sample or ask a question on Stack Overflow with the same? |
It is a typo, yes. Would you like to submit a PR to fix the typo? |
Sure @jzheaux , It is not a big deal actually. On the file spring-security/docs/modules/ROOT/partials/servlet/oauth2/client/rest-client-access-token-response-client.adoc line 260, This:
Should be:
|
Thanks @patpatpat123, please feel free to submit a PR. Did you see this comment?
|
I am having a hard time making it minimal, as it requires us to mock a token provider, a resource server, an observability platform, etc... With that said, the destination would be stackoverflow. Therefore, closing this, and attached the PR for review. Thank you |
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: