Skip to content

RestTemplate cannot support OAuth [SPR-6143] #10811

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

Closed
spring-projects-issues opened this issue Sep 22, 2009 · 5 comments
Closed

RestTemplate cannot support OAuth [SPR-6143] #10811

spring-projects-issues opened this issue Sep 22, 2009 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 22, 2009

Brian Topping opened SPR-6143 and commented

Overview: OAuth works by a series of shared secrets and hashes with those secrets on the URI and it's query parameters. In order for RestTemplate to support this increasingly important protocol, a transport must allow access (ideally, structured access) to the parameters that must be hashed as a part of the protocol.

As it stands, RestTemplate cannot support OAuth. There are two major issues:

First: It was attempted to do this with a RequestCallback for GET method calls, but failed because the URLConnection is created before the RequestCallback has an opportunity to add the necessary additional query parameters. It seems only appropriate that RequestCallback should have r/w access to the URI before it is used to open a connection.

Second: Even if this were fixed for GET method calls, http://oauth.net/core/1.0a#rfc.section.9.1.1 states that request parameters are collected from three locations when calculating signature hashes:

  • Parameters in the OAuth HTTP Authorization header (Authorization Header) excluding the realm parameter.
  • Parameters in the HTTP POST request body (with a content-type of application/x-www-form-urlencoded).
  • HTTP GET parameters added to the URLs in the query part (as defined by [RFC3986] (Berners-Lee, T., "Uniform Resource Identifiers (URI): Generic Syntax," .) section 3).

Unfortunately, because the request body of the POST method is an OutputStream, there is no way to inspect the body to find application/x-www-form-urlencoded data, parse it for parameters, and construct the Signature Base String.

Fixing the second problem highlights a need for structured body content renderers that can be modified before they are called to render when the connection is made. For instance, a basic BodyContentRenderer could write directly to the connection OutputStream (with no semantic difference than the current solution), and a more advanced one would emulate HTML form data, eventually rendering application/x-www-form-urlencoded data to the OutputStream, but not until the RequestCallback had an opportunity to modify the structured data of the form before it was rendered.


Affects: 3.0 M4

Issue Links:

4 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

Brian Topping commented

I probably have the wrong priority on this, but the problem does block my use of RestTemplate.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed, this is not a blocker in the sense of the term as we're using it here. It's rather a serious gap in functionality that's worth looking at.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

With the introduction of ClientHttpRequestInterceptors, I believe we can support OAuth. In fact, the Spring Social guys are already doing so :).

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 28, 2011

Dave Syer commented

N.B. #13050 is related and seems to be converging on a resolution.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 28, 2011

Dave Syer commented

On second thoughts, maybe #13050 isn't all that relevant, because that is more specifically about placeholder replacements (the order is important there as well). Also note: Spring Security OAuth is using a custom ClientHttpRequestFactory to construct the query (available in Spring 3.0, unlike the new interceptor).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants