You are here

public function OAuthStoreSQL::getServerForUri in Lingotek Translation 7.7

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

* Find the server details that might be used for a request * * The consumer_key must belong to the user or be public (user id is null) * *

Parameters

string uri uri of the server: * @param int user_id id of the logged on user * @exception OAuthException2 when no credentials found * @return array

Overrides OAuthStoreAbstract::getServerForUri

File

lib/oauth-php/library/store/OAuthStoreSQL.php, line 472

Class

OAuthStoreSQL

Code

public function getServerForUri($uri, $user_id) {

  // 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 .= '/';
  }

  // The owner of the consumer_key is either the user or nobody (public consumer key)
  $server = $this
    ->query_row_assoc('
					SELECT	ocr_id					as id,
							ocr_usa_id_ref			as user_id,
							ocr_consumer_key		as consumer_key,
							ocr_consumer_secret		as consumer_secret,
							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
					FROM oauth_consumer_registry
					WHERE ocr_server_uri_host = \'%s\'
					  AND ocr_server_uri_path = LEFT(\'%s\', LENGTH(ocr_server_uri_path))
					  AND (ocr_usa_id_ref = \'%d\' OR ocr_usa_id_ref IS NULL)
					ORDER BY ocr_usa_id_ref DESC, consumer_secret DESC, LENGTH(ocr_server_uri_path) DESC
					LIMIT 0,1
					', $host, $path, $user_id);
  if (empty($server)) {
    throw new OAuthException2('No server available for ' . $uri);
  }
  $server['signature_methods'] = explode(',', $server['signature_methods']);
  return $server;
}