- Click each of the links at the bottom of this page, starting with Register OAuth Server. After each one, you can look at the OAuth Options page to see the result.
- If all goes well on each of the links below, the final link should make a successful XML-RPC call using OAuth.
updateServer($oauth_server, $user->ID);
}
break;
case 'request':
$server = $oauth_store->getServerForUri($server_url, $user->ID);
if ($server) {
$token = @OAuthRequester::requestRequestToken($server['consumer_key'], $user->ID);
$token['consumer_key'] = $server['consumer_key'];
update_option('oauth_test_request_token', $token);
}
break;
case 'authorize':
$token = get_option('oauth_test_request_token');
$callback = add_query_arg('action', null, admin_url($GLOBALS['pagenow']));
$callback = add_query_arg('page', $_REQUEST['page'], $callback);
$authorize_url = $token['authorize_uri'];
$authorize_url = add_query_arg('oauth_token', rawurlencode($token['token']), $authorize_url);
$authorize_url = add_query_arg('oauth_callback', rawurlencode($callback), $authorize_url);
wp_redirect($authorize_url); exit;
break;
case 'access':
$request_token = get_option('oauth_test_request_token');
try {
$access_token = @OAuthRequester::requestAccessToken($request_token['consumer_key'], $request_token['token'], $user->ID);
}
catch (OAuthException $e) {
error_log('OAuthException - ' . var_export($e, true));
// Something wrong with the oauth_token.
// Could be:
// 1. Was already ok
// 2. We were not authorized
}
break;
}
}
function oauth_test_discovery($server_url) {
$xrds_path = WP_PLUGIN_DIR . '/xrds-simple/lib';
set_include_path($xrds_path . PATH_SEPARATOR . get_include_path());
require_once 'XRDS.php';
require_once 'XRDS/Discovery.php';
$disco = new XRDS_Discovery();
$xrds = $disco->discover($server_url);
if (is_a($xrds, 'XRDS')) {
$oauth_server = array(
'server_uri' => $server_url,
'signature_methods' => array(),
);
$service = $xrds->getService('http://oauth.net/core/1.0/endpoint/request');
foreach ($service->type as $type) {
if (strpos($type, 'http://oauth.net/core/1.0/signature') === 0) {
$oauth_server['signature_methods'][] = basename($type);
}
}
$oauth_server['request_token_uri'] = (string) $service->uri[0];
$oauth_server['authorize_uri'] = (string) $xrds->getServiceURI('http://oauth.net/core/1.0/endpoint/authorize');
$oauth_server['access_token_uri'] = (string) $xrds->getServiceURI('http://oauth.net/core/1.0/endpoint/access');
if ($static_service = $xrds->getService('http://oauth.net/discovery/1.0/consumer-identity/static')) {
$key = (string) $static_service->local_id[0];
$oauth_server['consumer_key'] = $key;
$oauth_server['consumer_secret'] = '';
}
return $oauth_server;
} else {
echo 'Unable to discovery OAuth Server at ' . $server_url . '
';
}
}
function oauth_test_options_page() {
$oauth_store = oauth_store();
$user = wp_get_current_user();
screen_icon('oauth');
?>
';
}
?>
getServerToken(get_option('oauth_test_consumer_key'), $request_token['token'], $user->ID);
if ($token) {
echo 'OAuth Token = ' . print_r($token, true) . '
';
echo '
';
}
} catch (OAuthException $e) {
}
?>
Register OAuth Server
Get Request Token
Authorize Token
Get Access Token
Make OAuth Authenticated Call
sign($user->ID);
$auth_header = $oauth_req->getAuthorizationHeader();
} catch (OAuthException $e) {
echo $e->getMessage();
return;
}
require_once( ABSPATH . WPINC . '/class-IXR.php' );
$xmlrpc = new IXR_Client($url);
$xmlrpc->debug = true;
list($header_name, $header_value) = split(':', $auth_header, 2);
$xmlrpc->headers[$header_name] = $header_value;
$result = $xmlrpc->query('blogger.getUserInfo', '', '', '');
echo '';
}
?>