You are here

public function OAuthStoreOracle::getSecretsForSignature in Lingotek Translation 7.5

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

* Find the server details for signing a request, always looks for an access token. * The returned credentials depend on which local user is making the request. * * The consumer_key must belong to the user or be public (user id is null) * * For signing we need all of the following: * * consumer_key consumer key associated with the server * consumer_secret consumer secret associated with this server * token access token associated with this server * token_secret secret for the access token * signature_methods signing methods supported by the server (array) * * @todo filter on token type (we should know how and with what to sign this request, and there might be old access tokens) *

Parameters

string uri uri of the server: * @param int user_id id of the logged on user * @param string name (optional) name of the token (case sensitive) * @exception OAuthException2 when no credentials found * @return array

Overrides OAuthStoreAbstract::getSecretsForSignature

File

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

Class

OAuthStoreOracle

Code

public function getSecretsForSignature($uri, $user_id, $name = '') {

  // Find a consumer key and token for the given uri
  $ps = parse_url($uri);
  $host = isset($ps['host']) ? $ps['host'] : 'localhost';
  $path = isset($ps['path']) ? $ps['path'] : '';
  if (empty($path) || substr($path, -1) != '/') {
    $path .= '/';
  }

  //
  $sql = "BEGIN SP_GET_SECRETS_FOR_SIGNATURE(:P_HOST, :P_PATH, :P_USER_ID, :P_NAME, :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_HOST', $host, 255);
  oci_bind_by_name($stmt, ':P_PATH', $path, 255);
  oci_bind_by_name($stmt, ':P_USER_ID', $user_id, 20);
  oci_bind_by_name($stmt, ':P_NAME', $name, 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, $getSecretsForSignatureList, null, null, OCI_FETCHSTATEMENT_BY_ROW);
  $secrets = $getSecretsForSignatureList[0];

  //
  // The owner of the consumer_key is either the user or nobody (public consumer key)

  /*$secrets = $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,
  				ocr_signature_methods	as signature_methods
  		FROM oauth_consumer_registry
  			JOIN oauth_consumer_token ON oct_ocr_id_ref = ocr_id
  		WHERE ocr_server_uri_host = \'%s\'
  		  AND ocr_server_uri_path = LEFT(\'%s\', LENGTH(ocr_server_uri_path))
  		  AND (ocr_usa_id_ref = %s OR ocr_usa_id_ref IS NULL)
  		  AND oct_usa_id_ref	  = %d
  		  AND oct_token_type      = \'access\'
  		  AND oct_name			  = \'%s\'
  		  AND oct_token_ttl       >= NOW()
  		ORDER BY ocr_usa_id_ref DESC, ocr_consumer_secret DESC, LENGTH(ocr_server_uri_path) DESC
  		LIMIT 0,1
  		', $host, $path, $user_id, $user_id, $name
  		);
           */
  if (empty($secrets)) {
    throw new OAuthException2('No server tokens available for ' . $uri);
  }
  $secrets['signature_methods'] = explode(',', $secrets['signature_methods']);
  return $secrets;
}