You are here

public function OAuthStoreOracle::getServerTokenSecrets in Lingotek Translation 7.7

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

* Get the token and token secret we obtained from a server. * *

Parameters

string consumer_key: * @param string token * @param string token_type * @param int user_id the user owning the token * @param string name optional name for a named token * @exception OAuthException2 when no credentials found * @return array

Overrides OAuthStoreAbstract::getServerTokenSecrets

File

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

Class

OAuthStoreOracle

Code

public function getServerTokenSecrets($consumer_key, $token, $token_type, $user_id, $name = '') {
  if ($token_type != 'request' && $token_type != 'access') {
    throw new OAuthException2('Unkown token type "' . $token_type . '", must be either "request" or "access"');
  }

  //
  $sql = "BEGIN SP_GET_SERVER_TOKEN_SECRETS(:P_CONSUMER_KEY, :P_TOKEN, :P_TOKEN_TYPE, :P_USER_ID, :P_ROWS, :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_TOKEN', $token, 255);
  oci_bind_by_name($stmt, ':P_TOKEN_TYPE', $token_type, 20);
  oci_bind_by_name($stmt, ':P_USER_ID', $user_id, 255);
  oci_bind_by_name($stmt, ':P_RESULT', $result, 20);

  //Bind the ref cursor
  $p_row = oci_new_cursor($this->conn);
  oci_bind_by_name($stmt, ':P_ROWS', $p_row, -1, OCI_B_CURSOR);

  //Execute the statement
  oci_execute($stmt);

  // treat the ref cursor as a statement resource
  oci_execute($p_row, OCI_DEFAULT);
  oci_fetch_all($p_row, $getServerTokenSecretsList, null, null, OCI_FETCHSTATEMENT_BY_ROW);
  $r = $getServerTokenSecretsList[0];

  //
  // Take the most recent token of the given type

  /*$r = $this->query_row_assoc('
  		SELECT	ocr_consumer_key		as consumer_key,
  				ocr_consumer_secret		as consumer_secret,
  				oct_token				as token,
  				oct_token_secret		as token_secret,
  				oct_name				as token_name,
  				ocr_signature_methods	as signature_methods,
  				ocr_server_uri			as server_uri,
  				ocr_request_token_uri	as request_token_uri,
  				ocr_authorize_uri		as authorize_uri,
  				ocr_access_token_uri	as access_token_uri,
  				IF(oct_token_ttl >= \'9999-12-31\', NULL, UNIX_TIMESTAMP(oct_token_ttl) - UNIX_TIMESTAMP(NOW())) as token_ttl
  		FROM oauth_consumer_registry
  				JOIN oauth_consumer_token
  				ON oct_ocr_id_ref = ocr_id
  		WHERE ocr_consumer_key = \'%s\'
  		  AND oct_token_type   = \'%s\'
  		  AND oct_token        = \'%s\'
  		  AND oct_usa_id_ref   = %d
  		  AND oct_token_ttl    >= NOW()
  		', $consumer_key, $token_type, $token, $user_id
  		);*/
  if (empty($r)) {
    throw new OAuthException2('Could not find a "' . $token_type . '" token for consumer "' . $consumer_key . '" and user ' . $user_id);
  }
  if (isset($r['signature_methods']) && !empty($r['signature_methods'])) {
    $r['signature_methods'] = explode(',', $r['signature_methods']);
  }
  else {
    $r['signature_methods'] = array();
  }
  return $r;
}