0

I am trying to get a request token from Bitbucket but I'm getting "BAD REQUEST - Could not verify OAuth request". I am doing this with drupal and here is the code I have so far:

$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);
Kim Janssens
  • 339
  • 4
  • 13

1 Answers1

0

You are providing a PLAINTEXT signature. If you are requesting a token with the provided signature not encrypted, change your oauth_signature_method to 'PLAINTEXT', so bitbucket knows you didn't encrypt it.

$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);

Also, you defined your options but never used them.