不使用bitbucket API检索令牌

时间:2015-04-20 10:49:49

标签: oauth drupal-7 bitbucket-api

我正在尝试从Bitbucket获取请求令牌,但我收到“BAD REQUEST - 无法验证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);

1 个答案:

答案 0 :(得分:0)

您正在提供PLAINTEXT签名。 如果您要求提供的签名未加密,请将您的oauth_signature_method更改为&#39; PLAINTEXT&#39;,因此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);

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