markatkinson85 / oauth-signpost

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

Unable to retrieveRequestToken with signpost-core-1.2.1.1 #49

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add signpost-core-1.2.1.1 and signpost-commonshttp4-1.2.1.1 to build 
path
2. Set consumer tokenkey and secret
3. Attemp to get OauthUrl to allow protected access

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

W/System.err(32162): Caused by: 
oauth.signpost.exception.OAuthCommunicationException: Communication with 
the service provider failed: 
https://www.google.com/accounts/OAuthGetRequestToken?
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbuzz
W/System.err(32162):    at 
oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.ja
va:214)
W/System.err(32162):    at 
oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProv
ider.java:69)
W/System.err(32162):    at 
org.lxtnow.testOauth.testoauth.onCreate(testoauth.java:62)
W/System.err(32162):    ... 13 more
W/System.err(32162): Caused by: java.io.FileNotFoundException: 
https://www.google.com/accounts/OAuthGetRequestToken?
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbuzz
W/System.err(32162):    at 
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.ge
tInputStream(HttpURLConnection.java:1061)
W/System.err(32162):    at 
org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.
getInputStream(HttpsURLConnection.java:252)
W/System.err(32162):    at 
oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLCon
nectionResponseAdapter.java:18)
W/System.err(32162):    at 
oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuth
Provider.java:228)
W/System.err(32162):    at 
oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.ja
va:189)
W/System.err(32162):    ... 15 more
D/AndroidRuntime(32162): Shutting down VM
W/dalvikvm(32162): threadid=3: thread exiting with uncaught exception 
(group=0x4001e170)
E/AndroidRuntime(32162): Uncaught handler: thread main exiting due to 
uncaught exception

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

version 1.2.1.1 for both core and commonshttp4
Also tried bundled version from OAuthGoogleExample from Git repository

Please provide any additional information below.

Original issue reported on code.google.com by lxt...@gmail.com on 29 May 2010 at 1:41

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
well, even with scope parameter. it's still failing.

here a sample of what I'm doing:
--------------------------------------------------------------------------------
----
provider = new DefaultOAuthProvider( REQUEST_TOKEN_URL + "?scope="
                + URLEncoder.encode( mscope, "utf-8" ), ACCESS_TOKEN_URL, 
AUTHORIZE_TOKEN_URL + "?scope="
                + URLEncoder.encode( mscope, "utf-8" ) + "&domain=" + consumerKey );

Did I miss something (if i get it clear, issue 36 is refering to this)?

Original comment by lxt...@gmail.com on 1 Jun 2010 at 11:25

GoogleCodeExporter commented 8 years ago
Please post an executable piece of code that reproduces this issues or I feel
inclined to reject this issue. Also, the example on GitHub does work. Before 
opening
bug report, post your problem on the mailing list, so we can rule out the 
chance that
the problem is with your code rather than Signpost's.

Original comment by m.kaepp...@gmail.com on 2 Jun 2010 at 7:54

GoogleCodeExporter commented 8 years ago
Here's a the piece of code you can add to a default android Activity with debug 
mode enabled.
And yes, the example from GitHub does work.
I'm also looking at what could mess while fetching the http request from 
android against oauth-signpost
as it should work with (including commonshttp4 lib to work on android)

--------------------------------------------------------------------------
private String mscope = "https://www.googleapis.com/auth/buzz";
private String REQUEST_TOKEN_URL = 
"https://www.google.com/accounts/OAuthGetRequestToken";
private String ACCESS_TOKEN_URL = 
"https://www.google.com/accounts/OAuthGetAccessToken";
private String AUTHORIZE_TOKEN_URL = 
"https://www.google.com/buzz/api/auth/OAuthAuthorizeToken";
private String callbackUrl = "lxtnowtest-android-app:///";

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String authUrl = null;
        consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);

        try
        {
            provider = new DefaultOAuthProvider( REQUEST_TOKEN_URL + "?scope="
                + URLEncoder.encode( mscope, "utf-8" ), ACCESS_TOKEN_URL,     
                  AUTHORIZE_TOKEN_URL + "?scope="
                + URLEncoder.encode( mscope, "utf-8" ) + "&domain=" + consumerKey );

            authUrl = provider.retrieveRequestToken( consumer, OAuth.OUT_OF_BAND );
        }
        catch ( Exception e )
        {
            try {
                throw new Exception( e );
            } catch (Exception e1) {

                e1.printStackTrace();
            }
        }

        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(authUrl + calbacklUrl));
        startActivity(i);
}
--------------------------------------------------------------------------------
-

Original comment by lxt...@gmail.com on 2 Jun 2010 at 7:33

GoogleCodeExporter commented 8 years ago
Do not use the DefaultOAuthProvider/Consumer classes in Android, use the 
CommonsHTTPOAuth versions.

Original comment by krahjerdi on 16 Aug 2010 at 10:35

GoogleCodeExporter commented 8 years ago
I'm using the following code which gives me an OAuthNotAuthorized exception in 
an android 2.1 activity which is using oauth-signpost 1.2.1.1 and I have 
removed my consumer_key and consumer_secret values (I have verified these are 
correct). Server keeps sending 401 with "Failed to validate oauth signature and 
token". This example is so trivial I don't know what could possibly be wrong 
with it.

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class TwitterActivity extends Activity {
    private CommonsHttpOAuthConsumer consumer;
    private CommonsHttpOAuthProvider provider;

    public final static String consumerKey =        "1234";
    public final static String consumerSecret =     "5678";
    private final String CALLBACKURL = "antweedoo://callback";

    protected static final String REQUEST_URL               = "https://api.twitter.com/oauth/request_token";
    protected static final String ACCESS_TOKEN_URL          = "https://api.twitter.com/oauth/access_token";
    protected static final String AUTH_URL                  = "https://api.twitter.com/oauth/authorize";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        doAuth();
    }

    private void doAuth() {
        final String TAG = getClass().getSimpleName();
        consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
        provider = new CommonsHttpOAuthProvider(REQUEST_URL, ACCESS_TOKEN_URL, AUTH_URL);

        try {
            String authURL = provider.retrieveRequestToken(consumer, CALLBACKURL);
            this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL))); // open the browser on the phone
            Log.i(TAG, "Success retrieving request token");
        } catch (OAuthMessageSignerException e) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.getMessage(), e);
        } catch (OAuthNotAuthorizedException e) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.getMessage(), e);
            Log.i(TAG+" response body: ", e.getResponseBody());
        } catch (OAuthExpectationFailedException e) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.getMessage(), e);
        } catch (OAuthCommunicationException e) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.getMessage(), e);
        }

    }
}

Original comment by catsgotm...@gmail.com on 28 Oct 2010 at 3:56

GoogleCodeExporter commented 8 years ago
Try this for your consumer (it did work for me):

import oauth.signpost.basic.DefaultOAuthConsumer;

DefaultOAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey, 
consumerSecret);

Original comment by lxt...@gmail.com on 28 Oct 2010 at 4:37

GoogleCodeExporter commented 8 years ago
I appreciate the help but I'm still having the same issue, here's the logcat

10-28 09:44:10.016: ERROR/TwitterActivity(1266): Authorization failed (server 
replied with a 401). This can happen if the consumer key was not correct or the 
signatures did not match.
10-28 09:44:10.016: ERROR/TwitterActivity(1266): 
oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed 
(server replied with a 401). This can happen if the consumer key was not 
correct or the signatures did not match.
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvi
der.java:239)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:18
9)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.
java:69)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
com.staticvoid.twitterapp3.TwitterActivity.doAuth(TwitterActivity.java:43)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
com.staticvoid.twitterapp3.TwitterActivity.onCreate(TwitterActivity.java:34)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.app.ActivityThread.access$2200(ActivityThread.java:119)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.os.Looper.loop(Looper.java:123)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
android.app.ActivityThread.main(ActivityThread.java:4363)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
java.lang.reflect.Method.invokeNative(Native Method)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
java.lang.reflect.Method.invoke(Method.java:521)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-28 09:44:10.016: ERROR/TwitterActivity(1266):     at 
dalvik.system.NativeStart.main(Native Method)

Original comment by catsgotm...@gmail.com on 28 Oct 2010 at 4:46

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hardly any different(moved constants and changed CommonsHttpOAuthConsumer to 
DefaultOAuthConsumer) but still gives me a OAuthNotAuthorizedException with a 
401, with the reason "Failed to validate oauth signature and token". I do have 
twitter settings as browser not client.
This is annoying, I can't even get past the first step of the OAuth process.

package com.staticvoid.twitterapp3;

import oauth.signpost.*;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.commonshttp.*;
import oauth.signpost.exception.*;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class TwitterActivity extends Activity {
    private static DefaultOAuthConsumer consumer;
    private static OAuthProvider provider;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        doAuth();
    }

    private void doAuth() {
        final String TAG = getClass().getSimpleName();

        OAuthCredentials oauth = new TwitterAPI(); // used to store constants related to OAuth

        consumer = new DefaultOAuthConsumer(oauth.getConsumerKey(), oauth.getConsumerSecret());
        provider = new CommonsHttpOAuthProvider(oauth.getRequestTokenUrl(),oauth.getAccessTokenUrl(), oauth.getAuthorizationUrl());

        try {
            String authURL = provider.retrieveRequestToken(consumer, null);
            Log.i(TAG, "Success retrieving request token");
            //Log.d(TAG, "Provider response: " + provider.getResponseParameters());
            //Log.d(TAG, "Authorization URL: " + provider.getAuthorizationWebsiteUrl());

            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL))); // open the browser on the phone

        } catch (OAuthMessageSignerException e) {

            Log.e(TAG, e.getMessage(), e);
        } catch (OAuthNotAuthorizedException e) {

            Log.e(TAG, e.getMessage(), e);
            Log.i(TAG+" response body: ", e.getResponseBody());

        } catch (OAuthExpectationFailedException e) {

            Log.e(TAG, e.getMessage(), e);
        } catch (OAuthCommunicationException e) {

            Log.e(TAG, e.getMessage(), e);
        }
    }
}

Original comment by catsgotm...@gmail.com on 28 Oct 2010 at 8:36

GoogleCodeExporter commented 8 years ago
holy cow I switched from signpost 1.2.1.1 to 1.2 and it resolved itself...

Original comment by catsgotm...@gmail.com on 28 Oct 2010 at 9:17

GoogleCodeExporter commented 8 years ago
I was getting the same error but it did not show up any more after I have set 
this to true on my provider.
oauthProvider.setOAuth10a(true);

Original comment by krishna....@gmail.com on 18 Nov 2010 at 7:36

GoogleCodeExporter commented 8 years ago
Please verify whether the device DATE and TIME are up to date. If not, then it 
might cause problems with the access token.

Original comment by vina.s...@gmail.com on 10 Feb 2012 at 9:08