One Star

[resolved] OAuth 1.0a with tRESTClient / tRESTResponse / tRESTRequest

Hi Folks,
I have a need to integrate with a REST API. I tried using a tJavaFlex component and dumped some java in like:
OAuthConsumer consumer = new OAuthConsumer(null, context.consumerKey, null, null);
consumer.setProperty(RSA_SHA1.PRIVATE_KEY, context.privateKey);
consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.accessToken = context.consumerKey;
accessor.tokenSecret = context.consumerSecret;
OAuthClient client = new OAuthClient(new HttpClient3());
OAuthMessage response = client.invoke(accessor, OAuthMessage.GET, context.endpointUrl + "contacts", null);
... but that just gives me an input stream, It feels wrong to go calling JAXB to convert it into an XML document and map it to a bean.
Surely there's a better way ?
1 ACCEPTED SOLUTION

Accepted Solutions
Employee

Re: [resolved] OAuth 1.0a with tRESTClient / tRESTResponse / tRESTRequest

The CXF code has been updated on the trunk and branches so you might want to give it a go in few days. Alternatively, if you fine with using WebClient then
you can use a typed API if preferred, something like WebClient.get(DOM4JDocument.class) would give you an instance of DOM4J response, etc
2 REPLIES
Employee

Re: [resolved] OAuth 1.0a with tRESTClient / tRESTResponse / tRESTRequest

Hi
I'd consider using CXF WebClient in this case, pity the existing OAuth1.0a client utility we ship does not offer a support for the RSA signatures, I'll update the code:
https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth/src/mai...
Have a look at the code, you can just create a header, then do
WebClient wc = WebClient.create("someaddress");
wc.header("Authorization", oauth1Header);
wc.get();
//etc
as I said, I'll update the utility code in meantime to make it simpler
HTH, Sergey
Employee

Re: [resolved] OAuth 1.0a with tRESTClient / tRESTResponse / tRESTRequest

The CXF code has been updated on the trunk and branches so you might want to give it a go in few days. Alternatively, if you fine with using WebClient then
you can use a typed API if preferred, something like WebClient.get(DOM4JDocument.class) would give you an instance of DOM4J response, etc