获取oauth_problem:Java中的signature_invalid错误

时间:2011-10-01 22:18:07

标签: java oauth signature

运行我的第一个OAuth提供程序/使用者示例。

我的提供程序是在Tomcat 7上运行的以下jsp

<%@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"); 
%>

它来自http://communitygrids.blogspot.com/2009/01/simple-oauth-client-and-server-examples.html

以下是基于抄写员的消费者方(控制台应用程序)

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;

public 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;
}

}`

当我运行客户端时,我收到来自提供商的错误响应

oauth_signature: onPnFrUtighWHU0UrERD0Wg7mII=

oauth_signature_base_string:GET&amp; http%3A%2F%2Flocalhost%3A9080%2FOAuthTest%2FOAuthTest.jsp&amp; 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)

任何指针都将非常感激。 THX

0 个答案:

没有答案