Skip to content
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

Some way to set an OAuth2RestTemplate ? #36

Closed
ignaciolarranaga opened this issue Nov 2, 2019 · 1 comment
Closed

Some way to set an OAuth2RestTemplate ? #36

ignaciolarranaga opened this issue Nov 2, 2019 · 1 comment

Comments

@ignaciolarranaga
Copy link

ignaciolarranaga commented Nov 2, 2019

Hi!, it might be nice some way to provide the restTemplate instead of the configurer.
I see there is a factory but didn't find a way to set it ?

I think I can workaround with something like this:

 builder.setRestTemplateConfigurer(restTemplate -> restTemplate.getInterceptors()
  .add((request, body, execution) -> {
    request.getHeaders().add("Authorization", format("Bearer %s", oauth2RestTemplate.getAccessToken()));
    return execution.execute(request, body);
  }));

But probably more elegant just to be able to provide the factory, or the rest template it self. Don't you guys think ?

@hdpe
Copy link
Owner

hdpe commented Nov 6, 2019

Hi, thanks for raising this.

The trouble with allowing clients to provide their own RestTemplate is that there's a certain minimum configuration they'll need to make: as written, Bowman needs an Apache HttpClient ClientHttpRequestFactory (or one that behaves similarly); we need a Jackson ObjectMapper configured with all the right modules (which then have a dependency back on the RestTemplate, to support the dynamic link-traversal proxying); we need the JSON+HAL accept headers added to its requests via an interceptor.

This configuration is sufficiently annoying that I figured it would be easier if Bowman sets up the RestTemplate and then allows clients to customise it afterwards with a RestTemplateConfigurer.

I appreciate this would be annoying when you already have a RestTemplate you want to use; however, the inelegance of adding all the Bowman-specific configuration to your RestTemplate will likely dwarf the inelegance of adding your Authorization header to the Bowman configuration.

As well as this, OAuth2RestTemplate and the rest of spring-security-oauth are in maintenance mode so I don't think we should go out of our way to provide bespoke support for it.

@hdpe hdpe closed this as completed Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants