You are here

public function OAuthServer::accessToken in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.3 lib/oauth-php/library/OAuthServer.php \OAuthServer::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/OAuthServer.php, line 282

Class

OAuthServer

Code

public function accessToken() {
  OAuthRequestLogger::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();
  }
  OAuthRequestLogger::flush();
  exit;
}