开发者

getting oauth_problem: signature_invalid error in Java

running my first OAuth provider/consumer example.

My provider is the below jsp running on Tomcat 7

<%@page import="net.oauth.*, net.oauth.server.*" %>
<%
  String consumerSecret="testsecret";
  String consumerKey="testkey";

  OAuthMessage message=OAuthServlet.getMessage(request,null);
  OAuthConsumer consumer=new OAuthConsumer(null, consumerKey, consumerSecret, null);
  OAuthAccessor accessor=new OAuthAccessor(consumer);

  SimpleOAuthValidator validator=new SimpleOAuthValidator();
  validator.validateMessage(message,accessor);

  System.out.println("It must have worked"); 
%>

It's derived from http://communitygrids.blogspot.com/2009/01/simple-oauth-client-and-server-examples.html

Below is my consumer side(a console app) based on the scribe lib

import org.apache.commons.codec.binary.Base64;
import org.scribe.builder.ServiceBuilder;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.oauth.OAuthService;
import api.TradeKingAPI;

pub开发者_运维技巧lic class OAuthScribeTest {

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

        String url = "http://localhost:9080/OAuthTest/OAuthTest.jsp";
        String consumerSecret="testsecret";
        String consumerKey="testkey";
        OAuthService service = new ServiceBuilder()
        .provider(TradeKingAPI.class)
        .apiKey(consumerKey)
        .apiSecret(consumerSecret)
        .build();

        Token accessToken = new Token(consumerKey, consumerSecret);

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

        service.signRequest(accessToken, request);
        Response response = request.send();
        System.out.println(response.getBody());

        int x = 0;
}

}`

when I run the client, I'm getting this error response from the provider

oauth_signature: onPnFrUtighWHU0UrERD0Wg7mII=

oauth_signature_base_string: GET&http%3A%2F%2Flocalhost%3A9080%2FOAuthTest%2FOAuthTest.jsp&oauth_consumer_key%3Dtestkey%26oauth_nonce%3D2098667235%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1317506767%26oauth_token%3Dtestkey%26oauth_version%3D1.0

oauth_problem: signature_invalid

oauth_signature_method: HMAC-SHA1 net.oauth.signature.OAuthSignatureMethod.validate(OAuthSignatureMethod.java:69) net.oauth.SimpleOAuthValidator.validateSignature(SimpleOAuthValidator.java:254) net.oauth.SimpleOAuthValidator.validateMessage(SimpleOAuthValidator.java:148) org.apache.jsp.OAuthTest_jsp._jspService(OAuthTest_jsp.java:75) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

any pointer will be greatly appreciated. thx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜