You are here

public function dropbox::get_request_token in Dropbox Client 7.3

Same name and namespace in other branches
  1. 7.4 dropbox.php \dropbox::get_request_token()
  2. 7 dropbox.php \dropbox::get_request_token()
  3. 7.2 dropbox.php \dropbox::get_request_token()

This is called to begin the oauth token exchange. This should only need to be called once for a user, provided they allow oauth access. It will return a URL that your site should redirect to, allowing the user to login and accept your application.

Parameters

string $callback the page on your site you wish to return to: after the user grants your application access.

Return value

mixed either the URL to redirect to, or if they specified HMAC signing an array with the token_secret and the redirect url

File

./dropbox.php, line 93

Class

dropbox

Code

public function get_request_token($callback) {
  $baseurl = self::SCHEME . '://' . self::HOST . '/' . self::API_VERSION . self::REQUEST_URI;

  //Generate an array with the initial oauth values we need
  $auth = build_auth_array($baseurl, $this->_consumer['key'], $this->_consumer['secret'], array(), $this->_consumer['method'], $this->_consumer['algorithm']);

  //Create the "Authorization" portion of the header
  $str = "";
  foreach ($auth as $key => $value) {
    $str .= ",{$key}=\"{$value}\"";
  }
  $str = 'Authorization: OAuth ' . substr($str, 1);

  //Send it
  $response = $this
    ->_connect($baseurl, $str, $this->_consumer['method']);

  //We should get back a request token and secret which

  //we will add to the redirect url.
  parse_str($response, $resarray);
  $callback = urlencode($callback);

  //Return the full redirect url and let the user decide what to do from there.
  $redirect = self::SCHEME . '://www.dropbox.com/' . self::API_VERSION . self::AUTHORIZE_URI . "?oauth_token={$resarray['oauth_token']}&oauth_callback={$callback}";
  return array(
    'token_secret' => $resarray['oauth_token_secret'],
    'redirect' => $redirect,
  );
}