请求OAuth访问令牌时出现问题



我正在为客户端构建一个库,以便与LinkedIn的API集成,目前正在进行OAuth实现。我可以请求初始令牌,这没有问题,并让用户向我的应用程序授予身份验证,但当我尝试使用oauth_token和oauth_verifier请求访问令牌时(以及我随请求发送的其余oauth信息),我会收到签名无效错误。

我发送的OAuth设置如下:

  • oauth_consumer_key
  • oauth_nonce
  • oauth_timestamp
  • oauth_签名_方法
  • oauth_version
  • oauth_token
  • oauth_verifier

我还添加了oauth_signature,它是所有这些密钥的签名版本。我用以下方法签署请求:

public void function signRequest(any req){
  var params = Arguments.req.getAllParameters();
  var secret = "#Variables.encoder.parameterEncodedFormat(getConsumer().getConsumerSecret())#&#Variables.encoder.parameterEncodedFormat(Arguments.req.getOAuthSecret())#";
  var base = '';
  params = Variables.encoder.encodedParameter(params, true, true);
  secret = toBinary(toBase64(secret));
  local.mac = createObject('java', 'javax.crypto.Mac').getInstance('HmacSHA1');
  local.key = createObject('java', 'javax.crypto.spec.SecretKeySpec').init(secret, local.mac.getAlgorithm());
  base = "#Arguments.req.getMethod()#&";
  base = base & Variables.encoder.parameterEncodedFormat(Arguments.req.getRequestUrl());
  base = "#base#&#Variables.encoder.parameterEncodedFormat(params)#";
  local.mac.init(local.key);
  local.mac.update(JavaCast('string', base).getBytes());
  Arguments.req.addParameter('oauth_signature', toString(toBase64(mac.doFinal())), true);
}

我知道它是有效的,因为我可以使用相同的方法来请求初始令牌(没有oauth_token或oauth_verifier参数),所以我认为这是我正在签名的参数的问题。(是的,在签名之前,我按字母顺序排列参数)

那么,是有一个我不应该包含在签名中的参数,还是另一个我应该包含的参数?

这是一个被加密的基本字符串的例子:

POST&https%3A%2F%2Fwww.linkedin.com%2Fuas%2Foauth%2FaccessToken&oauth_consumer_key%3Dwfs3ema3hi9s%26oauth_nonce%3D1887241367210%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1331326503%26oauth_token%3D8b83142a-d5a6-452e-80ef-6e75b1b0ce18%26oauth_verifier%3D94828%26oauth_version%3D1.0

发送POST请求时,需要将身份验证信息放在头中,而不是查询参数中。

有关信息,请参阅本页(查找"发送授权标头"):https://developer.linkedin.com/documents/common-issues-oauth-authentication

我怀疑这就是你遇到的问题。

好吧,这是一个愚蠢的答案,但问题是,当用户允许访问我的应用程序时,我没有看到oauth_token_secret出现,所以我仍然试图只使用消费者机密而不是同时使用消费者机密和oauth令牌机密来签署请求。

最新更新