skdevelopers / oauth-php

Example's can be found at SK Developers
http://www.skdevelopers.info/oauth
MIT License
1 stars 0 forks source link

PUT request using OAuth (java) fails to authenticate #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

1. perform PUT request using OAuth (java) using following code

import net.oauth.OAuth;
import net.oauth.OAuthAccessor;
import net.oauth.OAuthConsumer;
import net.oauth.OAuthMessage;
import net.oauth.ParameterStyle;
import net.oauth.client.OAuthClient;
import net.oauth.client.httpclient3.HttpClient3;
import net.oauth.signature.RSA_SHA1;

public class XeroTest
{

  public static void main(String[] args)
  {
    String apiURL="https://api.xero.com/api.xro/2.0/";

    String consumer_privateRSAKey="-----BEGIN RSA PRIVATE KEY-----\n"
        + "MIICXAIBAAKBgQDbpie9UmO0nRLMTIf3tNzqf1ARnNeFQHvaV6XHeNY9kfUvnHv8\n"
        + "8UuQLgB49BArG4AABv7QRAF7Azqn7jY6LgunMnW+rc9lxJsfGJuhRILc5Zh21Qmq\n"
        + "NOZLmSsZyLDoWo1VresG6eMqQBaqBb26u73aBccznC5ayuCYU1+EyWb0iwIDAQAB\n"
        + "AoGAJ4O2tnpx8XYogZRrCYcCDzWkI+cBZrl5DoiiDEaS1DTD1TLjo1eNbny4HQpb\n"
        + "NkYWOusHQFRbp9Om47sZClJqSe58ApkhWgFGneCjFCJCjP0WnBnF1wTgAkgLfgq+\n"
        + "3r2K2+Gptwhdg9ZimXgY3+mY5U+cJvJ/rbiPeCLWVs7HO1ECQQD57MrgaVpaSell\n"
        + "phzdlsy1iI4+4OY6ydXY6D2YBjqx4TpxahUOmFjN74/5XBZc3gn+1kMGtfW0ZFC4\n"
        + "hVmWd1h1AkEA4Pz2/bvJnD6OAGlRvM4de+/rtHjp9bPoLdTby0oFlr7sMafiImnG\n"
        + "5TlM+QFzrdmKGWi95A8UnPOwFSy7APN4/wJAN9Fv+jDtcg7h5sbz2XWtoLmv81Et\n"
        + "emHLthcgcoypnULNV7k2nLzf0Ja5lBrCD9mzZ8wYyi3ng3OIJ734pUdgZQJBANmb\n"
        + "cdzp807epgO52efOR3AnFofAZzFRJ6Ckf025M3yg/tvsL+ju/AObD1rLz7H3dP2s\n"
        + "c/WPrHU9sTJZyClcU8sCQF1886+5G+gf3Bg/sJRglRdpQ3jbWnxfRLDTCTnHwmIv\n"
        + "BsUN0XGNJ4SxChvc5rLvpTHpjTZYgZohJhuaI6WNFzg=\n"
        + "-----END RSA PRIVATE KEY-----";

    String consumerKey="MZFHMTC3NWFLZTCXNGE4YTG3NGVJMJ";
    String consumerSecret="OQDTQCDEXS21UURUVTSURLE9ARQ7UP";

    OAuthConsumer consumer = new OAuthConsumer(null,consumerKey, null, null);
    consumer.setProperty(RSA_SHA1.PRIVATE_KEY, consumer_privateRSAKey);
    consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
    consumer.setProperty(OAuthClient.PARAMETER_STYLE, ParameterStyle.AUTHORIZATION_HEADER);

    OAuthAccessor myAccessor = new OAuthAccessor(consumer);
    myAccessor.accessToken = consumerKey;
    myAccessor.tokenSecret = consumerSecret;

    try {
      // PUT Contacts example
      String postXML="<Contact>" +
            "<Name>Contact Name</Name>" +
            "<ContactNumber>002</ContactNumber>" +
            "</Contact>";
      OAuthClient client = new OAuthClient(new HttpClient3());
      OAuthMessage m = client.invoke(myAccessor, OAuthMessage.PUT, apiURL+"Contacts", OAuth.newList("xml",postXML));
      System.out.println(OAuthMessage.readAll(m.getBodyAsStream(), "UTF-8"));
    }
    catch ( Exception e ) {
      System.out.println(e.toString());
    }

  }
}

I expect to see a response from Xero with the newly created contact (like if I 
were to use POST method); instead the following is printed
11/08/2010 3:41:16 PM org.apache.commons.httpclient.HttpMethodDirector 
processWWWAuthChallenge
WARNING: Unable to respond to any of these challenges: {oauth=OAuth 
Realm="203.92.29.151"}
oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20si
gnature

I am using version from svn checkout of r1236

Original issue reported on code.google.com by hippysoy...@gmail.com on 11 Aug 2010 at 6:00

GoogleCodeExporter commented 9 years ago
ooops, wrong project! sorry!

feel free to close

Original comment by hippysoy...@gmail.com on 11 Aug 2010 at 6:02

GoogleCodeExporter commented 9 years ago
Easiest bug report fix ever :)

Original comment by brunobg%...@gtempaccount.com on 11 Aug 2010 at 7:54