You are here

public function OAuthServer::requestToken in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.3 lib/oauth-php/library/OAuthServer.php \OAuthServer::requestToken()

* Handle the request_token request. * Returns the new request token and request token secret. * * TODO: add correct result code to exception * *

Return value

string returned request token, false on an error

File

lib/oauth-php/library/OAuthServer.php, line 105

Class

OAuthServer

Code

public function requestToken() {
  OAuthRequestLogger::start($this);
  try {
    $this
      ->verify(false);
    $options = array();
    $ttl = $this
      ->getParam('xoauth_token_ttl', false);
    if ($ttl) {
      $options['token_ttl'] = $ttl;
    }

    // 1.0a Compatibility : associate callback url to the request token
    $cbUrl = $this
      ->getParam('oauth_callback', true);
    if ($cbUrl) {
      $options['oauth_callback'] = $cbUrl;
    }

    // Create a request token
    $store = OAuthStore::instance();
    $token = $store
      ->addConsumerRequestToken($this
      ->getParam('oauth_consumer_key', true), $options);
    $result = 'oauth_callback_confirmed=1&oauth_token=' . $this
      ->urlencode($token['token']) . '&oauth_token_secret=' . $this
      ->urlencode($token['token_secret']);
    if (!empty($token['token_ttl'])) {
      $result .= '&xoauth_token_ttl=' . $this
        ->urlencode($token['token_ttl']);
    }
    $request_token = $token['token'];
    header('HTTP/1.1 200 OK');
    header('Content-Length: ' . strlen($result));
    header('Content-Type: application/x-www-form-urlencoded');
    echo $result;
  } catch (OAuthException2 $e) {
    $request_token = false;
    header('HTTP/1.1 401 Unauthorized');
    header('Content-Type: text/plain');
    echo "OAuth Verification Failed: " . $e
      ->getMessage();
  }
  OAuthRequestLogger::flush();
  return $request_token;
}