Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>A bit of backstory/explanation</strong> </p> <p>I've been having a similar problem for the past couple of days, and had almost given up. Until I heard that the guy at my company that was putting up the services I was communicating with, had configured them to read the OAuth information from the query string instead of header parameters.</p> <p>So instead of reading it from the header parameter Authorization that Signpost puts into the request when you pass it on to be signed, for instance <code>[Authorization: OAuth oauth_consumer_key="USER", oauth_nonce="4027096421883800497", oauth_signature="Vd%2BJEb0KnUhEv1E1g3nf4Vl3SSM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1363100774", oauth_version="1.0"]</code>, the services where trying to read the query string, for example <code>http://myservice.mycompany.com?oauth_consumer_key=USER&amp;oauth_nonce=4027096421883800497&amp;oauth_signature=Vd%2BJEb0KnUhEv1E1g3nf4Vl3SSM%3D&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1363100774&amp;oauth_version=1.0</code>.</p> <p>The problem with this is that when I tried to sign the url and then build a HttpPost request with it, <strong>the url got a basestring with the prefix GET instead of POST which gave another signature then the one the service computed</strong>. Signpost isn't doing anything wrong, its url signing method is just by default set to GET with no other possibility available out of the box. This is so because you should read header parameters when doing POST, not the query string (Going to egg the house of that "colleague" of mine), and Signpost adds these when signing request which you should do when doing POST. </p> <p>The signingbasestring can be observed in the SigningBaseString class method generate in Signpost.</p> <p><strong>Solution</strong></p> <p>Now this is how I did it, but other ways may be possible or even better.</p> <ol> <li>Get the signpost source code and add it to your project. Can get it <a href="https://github.com/mttkay/signpost" rel="noreferrer">here</a></li> <li>Locate the <code>OAuthConsumer</code> class and change the signing method so that you can pass on information that the request should be POST. In my case I added a boolean like so <code>public String sign(String url, boolean POST)</code> </li> <li>Now you need to change the <code>sign</code> method in the <code>AbstractOAuthConsumer</code> class, which <code>CommonsHttpOAuthConsumer</code> and <code>DefaultOAuthConsumer</code> extend. In my case I added the boolean variable to the method and the following <code>if(POST) request.setMethod("POST");</code> right before the method calls <code>sign(request);</code></li> <li>Now the request is a Signpost specific object, HTTPRequest, so this will throw an error. You'll need to change it and add the method <code>public void setMethod(String method);</code>.</li> <li><p>This will cause an error in the following classes <code>HttpURLConnectionRequestAdapter</code>, <code>HttpRequestAdapter</code> and <code>UrlStringRequestAdapter</code>. You'll need to add the method implementation to them all, but in different flavors. For the first you'll add</p> <pre><code>public void setMethod(String method){ try { this.connection.setRequestMethod(method); } catch (ProtocolException e) { e.printStackTrace(); } } </code></pre> <p>for the second you'll add</p> <pre><code>public void setMethod(String method){ try { RequestWrapper wrapper = new RequestWrapper(this.request); wrapper.setMethod(method); request = wrapper; } catch (org.apache.http.ProtocolException e) { e.printStackTrace(); } } </code></pre> <p>and for the last you'll add</p> <pre><code>public void setMethod(String method){ mMethod = method; } </code></pre> <p>Be warned that I've only used and tried the first and last. But this at least gives you an idea about how to fix the problem, if you are having the same one as I.</p></li> </ol> <p>Hope this helps in anyway.</p> <p>-MrDresden</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload