You are here

public function OAuthStoreOracle::addServerToken in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/store/OAuthStoreOracle.php \OAuthStoreOracle::addServerToken()
  2. 7.2 lib/oauth-php/library/store/OAuthStoreOracle.php \OAuthStoreOracle::addServerToken()
  3. 7.4 lib/oauth-php/library/store/OAuthStoreOracle.php \OAuthStoreOracle::addServerToken()
  4. 7.5 lib/oauth-php/library/store/OAuthStoreOracle.php \OAuthStoreOracle::addServerToken()
  5. 7.6 lib/oauth-php/library/store/OAuthStoreOracle.php \OAuthStoreOracle::addServerToken()

* Add a request token we obtained from a server. * * @todo remove old tokens for this user and this ocr_id *

Parameters

string consumer_key key of the server in the consumer registry: * @param string token_type one of 'request' or 'access' * @param string token * @param string token_secret * @param int user_id the user owning the token * @param array options extra options, name and token_ttl * @exception OAuthException2 when server is not known * @exception OAuthException2 when we received a duplicate token

Overrides OAuthStoreAbstract::addServerToken

File

lib/oauth-php/library/store/OAuthStoreOracle.php, line 295

Class

OAuthStoreOracle

Code

public function addServerToken($consumer_key, $token_type, $token, $token_secret, $user_id, $options = array()) {
  if ($token_type != 'request' && $token_type != 'access') {
    throw new OAuthException2('Unknown token type "' . $token_type . '", must be either "request" or "access"');
  }

  // Maximum time to live for this token
  if (isset($options['token_ttl']) && is_numeric($options['token_ttl'])) {
    $ttl = intval($options['token_ttl']);
  }
  else {
    if ($token_type == 'request') {
      $ttl = intval($this->max_request_token_ttl);
    }
    else {
      $ttl = NULL;
    }
  }

  // Named tokens, unique per user/consumer key
  if (isset($options['name']) && $options['name'] != '') {
    $name = $options['name'];
  }
  else {
    $name = '';
  }

  //
  $sql = "BEGIN SP_ADD_SERVER_TOKEN(:P_CONSUMER_KEY, :P_USER_ID, :P_NAME, :P_TOKEN_TYPE, :P_TOKEN, :P_TOKEN_SECRET, :P_TOKEN_INTERVAL_IN_SEC, :P_RESULT); END;";

  // parse sql
  $stmt = oci_parse($this->conn, $sql) or die('Can not parse query');

  // Bind In and Out Variables
  oci_bind_by_name($stmt, ':P_CONSUMER_KEY', $consumer_key, 255);
  oci_bind_by_name($stmt, ':P_USER_ID', $user_id, 40);
  oci_bind_by_name($stmt, ':P_NAME', $name, 255);
  oci_bind_by_name($stmt, ':P_TOKEN_TYPE', $token_type, 20);
  oci_bind_by_name($stmt, ':P_TOKEN', $token, 255);
  oci_bind_by_name($stmt, ':P_TOKEN_SECRET', $token_secret, 255);
  oci_bind_by_name($stmt, ':P_TOKEN_INTERVAL_IN_SEC', $ttl, 40);
  oci_bind_by_name($stmt, ':P_RESULT', $result, 20);

  //Execute the statement
  oci_execute($stmt);

  //
  if (!$result) {
    throw new OAuthException2('Received duplicate token "' . $token . '" for the same consumer_key "' . $consumer_key . '"');
  }
}