gpt4 book ai didi

java - 验证签名请求 : signature_invalid

转载 作者:行者123 更新时间:2023-12-01 16:00:59 25 4
gpt4 key购买 nike

我正在尝试验证 OpenSocial 0.7 signed request ,使用该页面上的示例 Java 代码。我认为它应该以这种方式工作,但我仍然收到signature_invalid错误。

主要验证代码:

 // NOTE: req = HttpServletRequest

// check for hyves
if (!"hyves.nl".equals(req.getParameter("oauth_consumer_key"))) {
throw new RuntimeException("Only hyves supported");
}

// update hyves' certificate
getHyvesCert(req.getParameter("xoauth_signature_publickey"));

// construct message object
OAuthMessage oaMessage = new OAuthMessage(req.getMethod(), getRequestUrl(req), getParameters(req));

// validate message
// (will throw exception if invalid)
new SimpleOAuthValidator().validateMessage(oaMessage, new OAuthAccessor(OAUTH_CONSUMER_HYVES));

OAUTH_CONSUMER_HYVES:

 private static final OAuthServiceProvider OAUTH_THIS = new OAuthServiceProvider(null, null, null);
private static final OAuthConsumer OAUTH_CONSUMER_HYVES = new OAuthConsumer(null, "hyves.nl", null, OAUTH_THIS);

getHyvesCert:

 public void getHyvesCert(String name) {

synchronized(certLoadLock) {

// in reality this is code that downloads the certificate
// with the specified name, but this is the result
hyvesCert = "---BEGIN CERTIFICATE---- etc...";

OAUTH_CONSUMER_HYVES.setProperty(RSA_SHA1.X509_CERTIFICATE, hyvesCert);

}

}

方法getRequestUrlgetParametersdirectly copied from here .

最佳答案

我发现了问题。 getRequestUrl() 返回了错误的 URL,因为 Tomcat 位于 nginx 代理后面。因此,虽然发件人使用 URL“http://example.com/bla”来签署请求,但服务器使用“http://example.com:8080/bla” ”来验证它。

关于java - 验证签名请求 : signature_invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3931516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com