JerryBlight / oauth

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

OAuthException: Response body is incorrect. Can't extract token and secret #224

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. http://pastebin.com/T8qMWcfg outh.jsp
2. http://pastebin.com/KE8QCL2t outhcallback.jsp

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

Expected : 
Token accessToken = service.getAccessToken(requestToken, verifier);
call should have not errors.

Actual : 
org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract 
token and secret from this: 
'oauth_problem=signature_invalid&oauth_problem_advice=com.linkedin.security.auth
.pub.LoginDeniedInvalidAuthTokenException%20while%20obtaining%20request%20token%
20for%20%3APOST%26https%253A%252F%252Fapi.linkedin.com%252Fuas%252Foauth%252Facc
essToken%26oauth_consumer_key%253Di4t7bf5319a5%2526oauth_nonce%253D2295154173%25
26oauth_signature_method%253DHMAC-SHA1%2526oauth_timestamp%253D1335215773%2526oa
uth_token%253Daac2f41f-5d0f-4753-9d4d-2e0c018b64c4%2526oauth_verifier%253D07069%
2526oauth_version%253D1.0%0AOAU%3Ai4t7bf5319a5%7Caac2f41f-5d0f-4753-9d4d-2e0c018
b64c4%7C%2A01%7C%2A01%3A1335215773%3AKbo2ehezgJHlvhVY9TqwecmjnTc%3D'
    at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
    at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
    at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:82)

What version of the product are you using? On what operating system?
scribe-1.3.0.jar
on App Engine

NOTE: TwitterApi Works without any issues.
Also, I've tried the LinkedInExample and it works. The problem is with the 
callback.

How the outhcallback.jsp works

1. No session is used so I did below code on the callback again.
    service = new ServiceBuilder()
    .provider(LinkedInApi.class)
    .apiKey(OAuthConsumerKey.LINKEDIN_CONSUMER_KEY)
    .apiSecret(OAuthConsumerKey.LINKEDIN_CONSUMER_SECRET)
    .callback(callbackUrl)
    .build();
    requestToken = new Token(oAuthToken,OAuthConsumerKey.LINKEDIN_CONSUMER_SECRET);

Then using the verifier (which I already tested on LinkedInExample)

String oAuthVerifier = request.getParameter("oauth_verifier");
Verifier verifier = new Verifier(oAuthVerifier);

Then just called 
Token accessToken = service.getAccessToken(requestToken, verifier);

Then I got the attached exception.

My question is that, why does it work for Twitter and not in LinkedIn. Is there 
a special way I call Twitter, similar to Facebook API where no token should be 
passed?

And the one I cannot understand is on the Sample the flow is : 
OAuthService service = new ServiceBuilder()
Token requestToken = service.getRequestToken();
Verifier verifier = new Verifier(in.nextLine());
Token accessToken = service2.getAccessToken(requestToken, verifier);

But when I changed the code on did the same : 

I got this instead : 
org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract 
token and secret from this: 'oauth_problem=permission_unknown'
    at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
    at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
    at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:82)

Original issue reported on code.google.com by iceal.th...@gmail.com on 23 Apr 2012 at 9:44

GoogleCodeExporter commented 9 years ago
Also, I saw a couple of threads while googling. Something involving using 
HmacSHA1, but I cannot figure out where I need to add that on Scribe code.

Original comment by iceal.th...@gmail.com on 23 Apr 2012 at 9:49

GoogleCodeExporter commented 9 years ago
Typo : 

My question is that, why does it work for Twitter and not in LinkedIn. Is there 
a special way to call LinkedIn, similar to Facebook API where no token should 
be passed?

Original comment by iceal.th...@gmail.com on 23 Apr 2012 at 9:51

GoogleCodeExporter commented 9 years ago
i working on grails version 2+ ... and have the same problem .... 
everybody help @@@
this problem here :
Token accessToken = service.getAccessToken(rt, v);

Original comment by thaigiab...@gmail.com on 1 Nov 2012 at 3:32

a4200 commented 9 years ago

I am getting error: Exception in thread "main" org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=verifier_invalid' at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)

Token accessToken = service.getAccessToken(requestToken, verifier);

i am getting these value: Trading the Request Token for an Access Token...Token[0ec828f4e3d30c0d6bbc6e7a14c34553 , d5e06e0a91b51b82a9d52a9438e159fb] But not able to rid of this exception.

a4200 commented 9 years ago

complete cod is:

public static void main(String[] args) {

    final String MAGENTO_API_KEY = "1e4ba1c18fab07ce17297c468236c475";
    final String MAGENTO_API_SECRET = "d39d101b5daa21e4735c1a85ea059d94";
    final String MAGENTO_REST_API_URL = "http://localhost/magento/api/rest/";

    OAuthService service = new ServiceBuilder()
    .provider(MagentoThreeLeggedOAuth.class)
    .apiKey(MAGENTO_API_KEY)
    .apiSecret(MAGENTO_API_SECRET)
    .callback("http://sasken.com/MagentoScribe").build();
   // .build();
    System.out.println("" + service.getVersion());
    Scanner in = new Scanner(System.in);
    System.out.println("Magento's OAuth Workflow");
    System.out.println();
 // Obtain the Request Token
    System.out.println("Fetching the Request Token...");
    Token requestToken = service.getRequestToken();
    System.out.println("Got the Request Token!" +requestToken);
    System.out.println();
    System.out.println("Fetching the Authorization URL...");
   // MagentoThreeLeggedOAuth serv = new MagentoThreeLeggedOAuth();
   // System.out.println("seervice class:"+service.getClass());

   String authorizationUrl = service.getAuthorizationUrl(requestToken);

  String word ="";
 String token1 = requestToken.toString();
 System.out.println("token1 :" + token1.length());
 String[] strArray = token1.split(",");
 for(int i=0;i<= token1.length();i++)
 {
      word = strArray[1];
     //word = word.substring(1);
     word = word.replaceAll("]", "");

 }

 System.out.println("word vale is :" + word);

    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize Main here:");
    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");

   // String authUrl = serv.getAuthorizationUrl(requestToken);
   // System.out.println("authUrl::"+ authUrl);
   // Verifier verifier = new Verifier(authUrl);
//  Verifier verifier = new Verifier(in.nextLine());

   Verifier verifier = new Verifier(word);
 //   System.out.println("varifier::" +verifier.toString());
    //   Verifier verifier = new Verifier("7d4fa4e31d15fbc7b3c4e5eee936eb63");
     System.out.println("Trading the Request Token for an Access Token..." + requestToken );
     System.out.println("varifier::" + verifier.getValue());
     System.out.println("requestToken:" + requestToken.getToken());
        Token accessToken = service.getAccessToken(requestToken, verifier);
        System.out.println("Got the Access Token!");
        System.out.println("(if your curious it looks like this: "
                + accessToken + " )");
        System.out.println();
        OAuthRequest request = new OAuthRequest(Verb.GET, MAGENTO_REST_API_URL+ "/products?limit=2");
        service.signRequest(accessToken, request);
        Response response = request.send();
        System.out.println();
        System.out.println(response.getCode());
        System.out.println(response.getBody());
                System.out.println();

}

}