You are here

public function dropbox::get_access_token in Dropbox Client 7.4

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

This is called to finish the oauth token exchange. This too should only need to be called once for a user. The token returned should be stored in your database for that particular user.

Parameters

string $token this is the oauth_token returned with your callback url:

string $secret this is the token secret supplied from the request (Only required if using HMAC):

string $verifier this is the oauth_verifier returned with your callback url:

Return value

array access token and token secret

File

./dropbox.php, line 132

Class

dropbox

Code

public function get_access_token($secret, $token = false, $verifier = false) {

  //If no request token was specified then attempt to get one from the url
  if ($token === false && isset($_GET['oauth_token'])) {
    $token = $_GET['oauth_token'];
  }
  if ($verifier === false && isset($_GET['oauth_verifier'])) {
    $verifier = $_GET['oauth_verifier'];
  }

  //If all else fails attempt to get it from the request uri.
  if ($token === false && $verifier === false) {
    $uri = $_SERVER['REQUEST_URI'];
    $uriparts = explode('?', $uri);
    $authfields = array();
    parse_str($uriparts[1], $authfields);
    $token = $authfields['oauth_token'];
    $verifier = $authfields['oauth_verifier'];
  }
  $tokenddata = array(
    'oauth_token' => urlencode($token),
    'oauth_verifier' => urlencode($verifier),
  );
  if ($secret !== false) {
    $tokenddata['oauth_token_secret'] = urlencode($secret);
  }
  $baseurl = self::SCHEME . '://' . self::HOST . '/' . self::API_VERSION . self::ACCESS_URI;

  //Include the token and verifier into the header request.
  $auth = get_auth_header($baseurl, $this->_consumer['key'], $this->_consumer['secret'], $tokenddata, $this->_consumer['method'], $this->_consumer['algorithm'], $this->_access['oauth_token'], $this->_access['oauth_token_secret']);
  $response = $this
    ->_connect($baseurl, $auth, $this->_consumer['method']);

  //Parse the response into an array it should contain

  //both the access token and the secret key. (You only

  //need the secret key if you use HMAC-SHA1 signatures.)
  parse_str($response, $oauth);
  $this->_access = $oauth;

  //Return the token and secret for storage
  return $oauth;
}