<?php require_once dirname(__FILE__) . '/common.inc.php'; $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(); $token = $server->fetch_request_token($req); print $token . '&xoauth_token_expires=' . urlencode($store->token_expires($token)); } catch (OAuthException $e) { header('Content-type: text/plain;', true, 400); print $e->getMessage() . "\n\n"; var_dump($req); die; }
<?php require_once dirname(__FILE__) . '/common.inc.php'; $store = new OAuthWordpressStore(); $consumer = $store->new_consumer($_REQUEST['description']); echo 'oauth_consumer_key=' . urlencode($consumer->key) . '&xoauth_consumer_secret=' . urlencode($consumer->secret);
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 '<div class="wrap">'; echo ' <h2>Change Service Permissions</h2>'; echo ' <form method="post" action="">'; foreach ($userdata->oauth_consumers as $key => $values) { echo ' <h3>' . $store->lookup_consumer_description($key) . '</h3><ul>'; foreach ($services as $k => $v) { echo ' <li><input type="checkbox" ' . ($values[$k] && count($values[$k]) ? 'checked="checked"' : '') . ' name="services[' . htmlentities($key) . '][' . htmlentities($k) . ']" /> ' . $k . '</li>'; } echo ' </ul>'; } //end foreach echo ' <p><input type="submit" name="save" value="Save »" /></p>'; echo ' </form>'; echo '</div>'; }
<?php if (!$_REQUEST['oauth_token'] && !$_POST['authorize']) { die('No token passed'); } $NO_oauth = true; require_once dirname(__FILE__) . '/common.inc.php'; $store = new OAuthWordpressStore(); if (!$_POST['authorize']) { $token = $wpdb->escape($_REQUEST['oauth_token']); $consumer_key = $store->lookup_token('', 'request', $token); //verify token if (!$consumer_key) { die('Invalid token passed'); } } //end if ! POST authorize get_currentuserinfo(); if (!$userdata->ID) { $redirect_to = urlencode(get_bloginfo('wpurl') . '/wp-content/plugins/wp-oauth/authorize_token.php?oauth_token=' . urlencode($_REQUEST['oauth_token']) . '&oauth_callback=' . urlencode($_REQUEST['oauth_callback'])); header('Location: ' . get_bloginfo('wpurl') . '/wp-login.php?redirect_to=' . $redirect_to, true, 303); exit; } //end if ! userdata->ID if ($_POST['authorize']) { session_start(); $_REQUEST['oauth_callback'] = $_SESSION['oauth_callback']; unset($_SESSION['oauth_callback']); $token = $_SESSION['oauth_token']; unset($_SESSION['oauth_token']); $consumer_key = $_SESSION['oauth_consumer_key'];
function request_token(&$vars) { extract($vars); if (!(environment('openid_version') > 1) || (!$db->has_table('oauth_consumers') || !$db->has_table('oauth_tokens'))) { $db->create_openid_tables(); } wp_plugin_include(array('wp-oauth')); $consumerkey = $db->escape_string(urldecode($_POST['oauth_consumer_key'])); $consumer_result = $db->get_result("SELECT consumer_key FROM oauth_consumers WHERE consumer_key = '{$consumerkey}'"); if (!$db->num_rows($consumer_result) > 0) { $result = $db->get_result("INSERT INTO oauth_consumers (consumer_key, secret, description) VALUES ('{$consumerkey}', '', 'Unidentified Consumer')"); } $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); $params = array(); foreach ($_POST as $key => $val) { if (!($key == 'request_token')) { $params[$key] = $val; } } $req = OAuthRequest::from_request(); $token = $server->fetch_request_token($req); header('Status: 200 OK'); print $token->to_string() . '&xoauth_token_expires=' . urlencode($store->token_expires($token)); exit; }