array( array('content' => 'http://oauth.net/discovery/1.0') ), 'URI' => array( array('content' => '#oauth' ) ), ) ); register_xrd('oauth'); register_xrd_service('oauth', 'OAuth Request Token', array( 'Type' => array( array('content' => 'http://oauth.net/core/1.0/endpoint/request'), array('content' => 'http://oauth.net/core/1.0/parameters/uri-query'), array('content' => 'http://oauth.net/core/1.0/signature/HMAC-SHA1'), ), 'URI' => array( array('content' => get_bloginfo('wpurl').'/wp-content/plugins/wp-oauth/request_token.php' ) ), ) ); register_xrd_service('oauth', 'OAuth Authorize Token', array( 'Type' => array( array('content' => 'http://oauth.net/core/1.0/endpoint/authorize'), array('content' => 'http://oauth.net/core/1.0/parameters/uri-query'), ), 'URI' => array( array('content' => get_bloginfo('wpurl').'/wp-content/plugins/wp-oauth/authorize_token.php' ) ), ) ); register_xrd_service('oauth', 'OAuth Access Token', array( 'Type' => array( array('content' => 'http://oauth.net/core/1.0/endpoint/access'), array('content' => 'http://oauth.net/core/1.0/parameters/uri-query'), array('content' => 'http://oauth.net/core/1.0/signature/HMAC-SHA1'), ), 'URI' => array( array('content' => get_bloginfo('wpurl').'/wp-content/plugins/wp-oauth/access_token.php' ) ), ) ); register_xrd_service('oauth', 'OAuth Resources', array( 'Type' => array( array('content' => 'http://oauth.net/core/1.0/endpoint/resource'), array('content' => 'http://oauth.net/core/1.0/parameters/uri-query'), array('content' => 'http://oauth.net/core/1.0/signature/HMAC-SHA1'), ), ) ); register_xrd_service('oauth', 'OAuth Static Token', array( 'Type' => array( array('content' => 'http://oauth.net/discovery/1.0/consumer-identity/static'), ), 'LocalID' => array( array('content' => 'DUMMYKEY' ) ), ) ); }//end if ! oauth }//end if register_xrd $services = get_option('oauth_services'); $services['Post Comments'] = array('wp-comments-post.php'); $services['Edit and Create Entries and Categories'] = array('wp-app.php'); update_option('oauth_services', $services); $store = new OAuthWordpressStore(); $server = new OAuthServer($store); $sha1_method = new OAuthSignatureMethod_HMAC_SHA1(); $plaintext_method = new OAuthSignatureMethod_PLAINTEXT(); $server->add_signature_method($sha1_method); $server->add_signature_method($plaintext_method); try { $req = OAuthRequest::from_request(); list($consumer, $token) = $server->verify_request($req); $userid = $store->user_from_token($consumer->key, $token->key); $authed = get_usermeta($userid, 'oauth_consumers'); $authed = $authed[$consumer->key]; if($authed && $authed['authorized']) { $allowed = false; foreach($authed as $ends) if(is_array($ends)) foreach($ends as $end) if(strstr($_SERVER['SCRIPT_URI'], $end)) $allowed = true; if($allowed) set_current_user($userid); }//end if } catch (OAuthException $e) {/* We may not be doing OAuth at all. */} }//end function oauth_accept //if(!$NO_oauth) oauth_accept(); function oauth_page() { global $wpdb; if($_POST['new_consumer']) { $store = new OAuthWordpressStore(); $store->new_consumer($_POST['new_consumer']); echo '

New Consumer pair generated.

'; }//end if new consumer echo '
'; echo '

OAuth Consumers

'; $consumers = $wpdb->get_results("SELECT description, consumer_key, secret FROM {$wpdb->prefix}oauth_consumers", ARRAY_A); echo ''; echo '

Add OAuth Consumer

'; echo '
'; echo ''; echo ''; echo '
'; echo '

Endpoints

'; echo '
'; echo '
Request token endpoint
'; echo '
'.get_bloginfo('wpurl').'/wp-content/plugins/wp-oauth/request_token.php
'; echo '
Authorize token endpoint
'; echo '
'.get_bloginfo('wpurl').'/wp-content/plugins/wp-oauth/authorize_token.php
'; echo '
Access token endpoint
'; echo '
'.get_bloginfo('wpurl').'/wp-content/plugins/wp-oauth/access_token.php
'; echo '
'; $anid = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_type='post' ORDER BY post_date DESC LIMIT 1"); echo 'Click here for a test page »'; }//end function oauth_page function oauth_tab($s) { add_submenu_page('options-general.php', 'OAuth', 'OAuth', 1, __FILE__, 'oauth_page'); return $s; }//end function add_action('admin_menu', 'oauth_tab'); function oauth_services_render() { global $userdata; get_currentuserinfo(); $services = get_option('oauth_services'); if($_POST['save']) { $userdata->oauth_consumers = array(); if(!$_POST['services']) $_POST['services'] = array(); foreach($_POST['services'] as $key => $value) { $service = array('authorized' => true); foreach($services as $k => $v) if(in_array($k, array_keys($value))) $service[$k] = $v; $userdata->oauth_consumers[$key] = $service; }//end foreach services update_usermeta($userdata->ID, 'oauth_consumers', $userdata->oauth_consumers); }//end if save require_once dirname(__FILE__).'/OAuthWordpressStore.php'; $store = new OAuthWordpressStore(); echo '
'; echo '

Change Service Permissions

'; echo '
'; foreach($userdata->oauth_consumers as $key => $values) { echo '

'.$store->lookup_consumer_description($key).'

    '; foreach($services as $k => $v) echo '
  • '.$k.'
  • '; echo '
'; }//end foreach echo '

'; echo '
'; echo '
'; }//end function oauth_services_render function oauth_services_tab($s) { add_submenu_page('profile.php', 'Services', 'Services', 1, __FILE__, 'oauth_services_render'); return $s; }//end function add_action('admin_menu', 'oauth_services_tab'); ?>