sander120786 / oauth-signpost

Automatically exported from code.google.com/p/oauth-signpost
0 stars 0 forks source link

isOAuth10a in reconstituted DefaultOAuthProvider always false resulting in HTTP 401 responses #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I am creating the request tokens out-of-band.  The DefaultOAuthProvider
will set isOAuth10a to true in retrieveRequestToken() and I get the
consumer token and token secret, which I store for later use.

I need to reconstitute the OAuthProvider at a later time to invoke
retrieveAccessToken() with the PIN that the user enters.  I can create the
DefaultOAuthConsumer and initialize the token and token secret.  The
OAuthProvider, though, has isOAuth10a set to false by default and there is
no way to set it to true (no setter method and it is a private property).

As such, I always get an HTTP 401 error.

In Eclipse, I can set a breakpoint before the call to retrieveAccessToken()
and reach behind the scenes and set isOAuth10a to true before the call is
made and I get a successful HTTP 200 return.

What is the expected output? What do you see instead?

I would expect there to be some way to programatically initialize
isOAuth10a to true.

I could create my own implementation that is essentially a copy of
DefaultOAuthProvider, but with a setter for isOAuth10a; however, I'd rather
not replicate code and have to keep them in sync.

What version of the product are you using? On what operating system?

snapshot-core-1.1-SNAPSHOT downloaded 2009.06.24

Please provide any additional information below.  Here is the example
Twitter code modified to emulate complete reconstitution of the consumer
and provider.

public static void main(String[] args) throws Exception {

        OAuthConsumer consumer = new DefaultOAuthConsumer(
                CONSUMER_KEY,
                CONSUMER_SECRET,
                SignatureMethod.HMAC_SHA1);

        OAuthProvider provider = new DefaultOAuthProvider(consumer,
                "http://twitter.com/oauth/request_token",
                "http://twitter.com/oauth/access_token",
                "http://twitter.com/oauth/authorize");

        System.out.println("Fetching request token from Twitter...");

        // we do not support callbacks, thus pass OOB
        String authUrl = provider.retrieveRequestToken(OAuth.OUT_OF_BAND);

        System.out.println("Request token: " + consumer.getToken());
        System.out.println("Token secret: " + consumer.getTokenSecret());

        System.out.println("Now visit:\n" + authUrl
                + "\n... and grant this app authorization");
        System.out.println("Enter the PIN code and hit ENTER when you're
done:");

        BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
        String pin = br.readLine();

        String requestToken = consumer.getToken();
        String requestTokenSecret = consumer.getTokenSecret();

        // Save the requestToken and requestTokenSecret away.  Pretend the rest
        // of this is a whole new thread with reconstituted consumer/provider.

        System.out.println("Fetching access token from Twitter...");

        OAuthConsumer consumer2 = new DefaultOAuthConsumer(
                CONSUMER_KEY,
                CONSUMER_SECRET,
                SignatureMethod.HMAC_SHA1);

        consumer2.setTokenWithSecret(requestToken, requestTokenSecret);

        OAuthProvider provider2 = new DefaultOAuthProvider(consumer2,
                "http://twitter.com/oauth/request_token",
                "http://twitter.com/oauth/access_token",
                "http://twitter.com/oauth/authorize");

        // Here I can set a breakpoint in Eclipse, reach behind the scenes
        // and set provider2's isOAuth10a to true and it will work
        provider2.retrieveAccessToken(pin);

        System.out.println("Access token: " + consumer.getToken());
        System.out.println("Token secret: " + consumer.getTokenSecret());

        URL url = new URL("http://twitter.com/statuses/mentions.xml");
        HttpURLConnection request = (HttpURLConnection) url.openConnection();

        consumer2.sign(request);

        System.out.println("Sending request to Twitter...");
        request.connect();

        System.out.println("Response: " + request.getResponseCode() + " "
                + request.getResponseMessage());
    }

Original issue reported on code.google.com by mayfield...@gmail.com on 24 Jun 2009 at 9:01

GoogleCodeExporter commented 8 years ago

Original comment by m.kaepp...@gmail.com on 25 Jun 2009 at 12:06

GoogleCodeExporter commented 8 years ago
This issue was closed by r53.

Original comment by m.kaepp...@gmail.com on 27 Jun 2009 at 3:17