You are here

public function LingotekOAuthServer::accessToken in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.4 lib/oauth-php/library/LingotekOAuthServer.php \LingotekOAuthServer::accessToken()
  2. 7.5 lib/oauth-php/library/LingotekOAuthServer.php \LingotekOAuthServer::accessToken()
  3. 7.6 lib/oauth-php/library/LingotekOAuthServer.php \LingotekOAuthServer::accessToken()

* Exchange a request token for an access token. * The exchange is only succesful iff the request token has been authorized. * * Never returns, calls exit() when token is exchanged or when error is returned.

File

lib/oauth-php/library/LingotekOAuthServer.php, line 282

Class

LingotekOAuthServer

Code

public function accessToken() {
  LingotekOAuthRequestLogger::start($this);
  try {
    $this
      ->verify('request');
    $options = array();
    $ttl = $this
      ->getParam('xoauth_token_ttl', false);
    if ($ttl) {
      $options['token_ttl'] = $ttl;
    }
    $verifier = $this
      ->getParam('oauth_verifier', false);
    if ($verifier) {
      $options['verifier'] = $verifier;
    }
    $store = OAuthStore::instance();
    $token = $store
      ->exchangeConsumerRequestForAccessToken($this
      ->getParam('oauth_token', true), $options);
    $result = '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']);
    }
    header('HTTP/1.1 200 OK');
    header('Content-Length: ' . strlen($result));
    header('Content-Type: application/x-www-form-urlencoded');
    echo $result;
  } catch (OAuthException2 $e) {
    header('HTTP/1.1 401 Access Denied');
    header('Content-Type: text/plain');
    echo "OAuth Verification Failed: " . $e
      ->getMessage();
  }
  LingotekOAuthRequestLogger::flush();
  exit;
}