简体   繁体   中英

2 legged OAuth using Scribe - java equivalent of php

I'm trying to use scribe to implement 2 legged OAuth in Java with reference to php code. I believe I'm very close to cracking this. My current error is:

**OAuth - response.getBody: Problem: signature_invalid | Advice: > |

response.getCode(): 200**

I suspect that this has something to do with the form of the token or lack of consumer object while signing the request. In php, the code is:

$consumer = new OAuthConsumer($consumer_key, $consumer_secret); 

//post transaction to pesapal

$iframe_src = OAuthRequest::from_consumer_and_token($consumer, $token, "GET", $iframelink, $params);
$iframe_src->set_parameter("oauth_callback", $callback_url);
$iframe_src->set_parameter("pesapal_request_data", $post_xml);
**$iframe_src->sign_request($signature_method, $consumer, $token);**   

From the last line, to sign the request, the consumer is also passed as a parameter.

My code is as follows:

OAuthService service = new ServiceBuilder()
         .provider(something.class)
         .signatureType(SignatureType.QueryString)
         .apiKey(consumer_key)
         .apiSecret(consumer_secret)
         .callback(callback_url)
         .build();

Token token = new Token("", "");

OAuthRequest request = new OAuthRequest(Verb.GET, iframelink);

request.addBodyParameter("pesapal_request_data", post_xml);
request.addOAuthParameter(OAuthConstants.SIGN_METHOD, signature_method);
service.signRequest(token, request);

Response response = request.send();

Can someone please show me where I may have gone wrong ? I know that I'm close - very close ....

Try to change $iframelink = http://www.pesapal.com/api/PostPesapalDirectOrderV4 to $iframelink = https://www.pesapal.com/api/PostPesapalDirectOrderV4

Had the same issue when live changing from http to https sorted me out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM