Java 中出现 oauth_problem:signature_invalid 错误

发布于 2024-12-07 14:13:35 字数 3098 浏览 0 评论 0原文

运行我的第一个 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&http%3A%2F%2Flocalhost%3A9080%2FOAuthTest%2FOAuthTest.jsp&oauth_consumer_key%3Dtestkey%26oauth_nonce%3D2098 667235%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1317506767%26oauth_token%3Dtestkey%26oauth_version%3D1.0

oauth_问题: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)

任何指针将不胜感激。谢谢

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;

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

}`

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文