0

我正在尝试从 Bitbucket 获取请求令牌,但我收到“错误请求 - 无法验证 OAuth 请求”。我正在使用 drupal 执行此操作,这是我目前拥有的代码:

$key = "MY_KEY";
$secret ="MY_SECRET";
$timestamp = time();
$nonce = (int) (rand() * 100000000);
$callback = 'http://www.google.com'; //'htt//url('<front>', array('absolute' => TRUE)); //DRUPAL_ROOT . "/toolkittens/git";

$url = "https://bitbucket.org/api/1.0/oauth/request_token";

$data = array(
  'oauth_nonce'             => $nonce,
  'oauth_timestamp'         => $timestamp,
  'oauth_consumer_key'      => $key,
  'oauth_signature_method'  => 'PLAINTEXT',
  'oauth_signature'         => 'thisismysig',
  'oauth_callback'          => $callback,
  'oauth_version'           => '1.0',
);

$options = array(
  'method'  => 'POST',
  'data' => drupal_http_build_query($data),
  'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);

return drupal_http_request($url, $options);
4

1 回答 1

0

您提供的是 PLAINTEXT 签名。如果您请求的令牌提供的签名未加密,请将您的 oauth_signature_method 更改为“PLAINTEXT”,以便 bitbucket 知道您没有对其进行加密。

$key = "MY_KEY";
$signature = "MY_SIGNATURE"; //I think this is your secret from bitbucket
$timestamp = time();
$nonce = rand();
$callback = DRUPAL_ROOT . "/toolkittens/git";

$url = "https://bitbucket.org/api/1.0/oauth/request_token";

$data = array(
  'oauth_nonce'             => $nonce,
  'oauth_timestamp'         => $timestamp,
  'oauth_consumer_key'      => $key,
  'oauth_signature_method'  => 'PLAINTEXT',
  'oauth_signature'         => $signature,
  'oauth_callback'          => $callback,
  'oauth_version'           => '1.0',
);

$options = array(
  'method'  => 'POST',
  'data'    => $data,
  'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);

$full_url = url($url, array('query' => $data));
return drupal_http_request($full_url);

此外,您定义了您的选项,但从未使用过它们。

于 2015-04-20T14:07:45.817 回答