You are here

public function LingotekOAuthServer::requestToken in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/LingotekOAuthServer.php \LingotekOAuthServer::requestToken()
  2. 7.5 lib/oauth-php/library/LingotekOAuthServer.php \LingotekOAuthServer::requestToken()
  3. 7.6 lib/oauth-php/library/LingotekOAuthServer.php \LingotekOAuthServer::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/LingotekOAuthServer.php, line 105

Class

LingotekOAuthServer

Code

public function requestToken() {
  LingotekOAuthRequestLogger::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();
  }
  LingotekOAuthRequestLogger::flush();
  return $request_token;
}