Пример #1
0
 function redirect_incoming_verify($request)
 {
     if (!isset($request['kr_nonce'])) {
         $kr_nonce = wp_create_nonce('keyring-verify');
         $nonce = wp_create_nonce('keyring-verify-' . $this->get_name());
         wp_safe_redirect(Keyring_Util::admin_url($this->get_name(), array('action' => 'verify', 'kr_nonce' => $kr_nonce, 'nonce' => $nonce, 'state' => $request['state'], 'code' => $request['code'])));
         exit;
     }
 }
Пример #2
0
 function basic_ui_intro()
 {
     echo '<p>' . sprintf(__('If you haven\'t already, you\'ll need to <a href="%s">create a new app at Foursquare</a>. You should only need to worry about these settings:', 'keyring'), 'https://foursquare.com/developers/register') . '</p>';
     echo '<ol>';
     echo '<li>' . __("<strong>Your app name</strong>: enter whatever you like, maybe your website's name?", 'keyring') . '</li>';
     echo '<li>' . sprintf(__("<strong>Download / welcome page url</strong>: just enter your website's URL, <code>%s</code>", 'keyring'), get_bloginfo('url')) . '</li>';
     echo '<li>' . sprintf(__("<strong>Redirect URI(s)</strong>: Copy-paste this, <code>%s</code>", 'keyring'), Keyring_Util::admin_url('foursquare', array('action' => 'verify'))) . '</li>';
     echo '<li>' . __("<strong>New users can connect via the web</strong>: check the box", 'keyring') . '</li>';
     echo '</ol>';
     echo '<p>' . __("Once you've saved those changes, copy the <strong>Client id</strong> value into the <strong>API Key</strong> field, and the <strong>Client secret</strong> value into the <strong>API Secret</strong> field and click save (you don't need an App ID value for Foursquare).", 'keyring') . '</p>';
 }
Пример #3
0
 function __construct()
 {
     parent::__construct();
     // Nonces for the callback URL, which is used during the verify step
     $kr_nonce = wp_create_nonce('keyring-verify');
     $nonce = wp_create_nonce('keyring-verify-' . $this->get_name());
     $this->callback_url = Keyring_Util::admin_url($this->get_name(), array('action' => 'verify', 'kr_nonce' => $kr_nonce, 'nonce' => $nonce));
     if (!class_exists('OAuthRequest')) {
         require dirname(dirname(dirname(__FILE__))) . '/oauth-php/OAuth.php';
     }
 }
Пример #4
0
 function __construct()
 {
     parent::__construct();
     // Enable "basic" UI for entering key/secret
     if (!KEYRING__HEADLESS_MODE) {
         add_action('keyring_facebook_manage_ui', array($this, 'basic_ui'));
         add_filter('keyring_facebook_basic_ui_intro', array($this, 'basic_ui_intro'));
     }
     $this->set_endpoint('authorize', 'https://www.facebook.com/dialog/oauth', 'GET');
     $this->set_endpoint('access_token', 'https://graph.facebook.com/oauth/access_token', 'GET');
     $this->set_endpoint('self', 'https://graph.facebook.com/me', 'GET');
     $creds = $this->get_credentials();
     $this->app_id = $creds['app_id'];
     $this->key = $creds['key'];
     $this->secret = $creds['secret'];
     $kr_nonce = wp_create_nonce('keyring-verify');
     $nonce = wp_create_nonce('keyring-verify-facebook');
     $this->redirect_uri = Keyring_Util::admin_url(self::NAME, array('action' => 'verify', 'kr_nonce' => $kr_nonce, 'nonce' => $nonce));
     $this->requires_token(true);
     add_filter('keyring_facebook_request_token_params', array($this, 'filter_request_token'));
 }
Пример #5
0
 function basic_ui_intro()
 {
     echo '<p>' . sprintf(__('To get started, <a href="%1$s">register an OAuth client on Instagram</a>. The most important setting is the <strong>OAuth redirect_uri</strong>, which should be set to <code>%2$s</code>. You can set the other values to whatever you like.', 'keyring'), 'http://instagram.com/developer/clients/register/', Keyring_Util::admin_url('instagram', array('action' => 'verify'))) . '</p>';
     echo '<p>' . __("Once you've saved those changes, copy the <strong>CLIENT ID</strong> value into the <strong>API Key</strong> field, and the <strong>CLIENT SECRET</strong> value into the <strong>API Secret</strong> field and click save (you don't need an App ID value for Instagram).", 'keyring') . '</p>';
 }
Пример #6
0
 function verified($id, $request_token = null)
 {
     $c = get_called_class();
     // If something else needs to be done, do it
     do_action('keyring_connection_verified', $c::NAME, $id, $request_token);
     // Back to Keyring admin, with ?service=SERVICE&created=UNIQUE_ID&kr_nonce=NONCE
     $kr_nonce = wp_create_nonce('keyring-created');
     $url = apply_filters('keyring_verified_redirect', Keyring_Util::admin_url($c::NAME, array('action' => 'created', 'id' => $id, 'kr_nonce' => $kr_nonce)), $c::NAME);
     Keyring_Util::debug('Verified connection, redirect to ' . $url);
     wp_safe_redirect($url);
     exit;
 }
Пример #7
0
 static function connect_to($service, $for)
 {
     Keyring_Util::debug('Connect to: ' . $service);
     // Redirect into Keyring's auth handler if a valid service is provided
     $kr_nonce = wp_create_nonce('keyring-request');
     $request_nonce = wp_create_nonce('keyring-request-' . $service);
     wp_safe_redirect(Keyring_Util::admin_url($service, array('action' => 'request', 'kr_nonce' => $kr_nonce, 'nonce' => $request_nonce, 'for' => $for)));
     exit;
 }
Пример #8
0
 function basic_ui()
 {
     if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'keyring-manage-' . $this->get_name())) {
         Keyring::error(__('Invalid/missing management nonce.', 'keyring'));
         exit;
     }
     // Common Header
     echo '<div class="wrap">';
     screen_icon('ms-admin');
     echo '<h2>' . __('Keyring Service Management', 'keyring') . '</h2>';
     echo '<p><a href="' . Keyring_Util::admin_url(false, array('action' => 'services')) . '">' . __('&larr; Back', 'keyring') . '</a></p>';
     echo '<h3>' . sprintf(__('%s API Credentials', 'keyring'), esc_html($this->get_label())) . '</h3>';
     // Handle actually saving credentials
     if (isset($_POST['api_key']) && isset($_POST['api_secret'])) {
         // Store credentials against this service
         $this->update_credentials(array('key' => stripslashes($_POST['api_key']), 'secret' => stripslashes($_POST['api_secret']), 'redirect_uri' => stripslashes($_POST['redirect_uri'])));
         echo '<div class="updated"><p>' . __('Credentials saved.', 'keyring') . '</p></div>';
     }
     $api_key = $api_secret = $redirect_uri = '';
     if ($creds = $this->get_credentials()) {
         $api_key = $creds['key'];
         $api_secret = $creds['secret'];
         $redirect_uri = $creds['redirect_uri'];
     }
     echo apply_filters('keyring_' . $this->get_name() . '_basic_ui_intro', '');
     if (!$redirect_uri) {
         $redirect_uri = Keyring_Util::admin_url($this->get_name(), array('action' => 'verify'));
     }
     // Output basic form for collecting key/secret
     echo '<form method="post" action="">';
     echo '<input type="hidden" name="service" value="' . esc_attr($this->get_name()) . '" />';
     echo '<input type="hidden" name="action" value="manage" />';
     wp_nonce_field('keyring-manage', 'kr_nonce', false);
     wp_nonce_field('keyring-manage-' . $this->get_name(), 'nonce', false);
     echo '<table class="form-table">';
     echo '<tr><th scope="row">' . __('Client ID', 'keyring') . '</th>';
     echo '<td><input type="text" name="api_key" value="' . esc_attr($api_key) . '" id="api_key" class="regular-text"></td></tr>';
     echo '<tr><th scope="row">' . __('Client Secret', 'keyring') . '</th>';
     echo '<td><input type="text" name="api_secret" value="' . esc_attr($api_secret) . '" id="api_secret" class="regular-text"></td></tr>';
     echo '<tr><th scope="row">' . __('Redirect URI', 'keyring') . '</th>';
     echo '<td><input type="text" name="redirect_uri" value="' . esc_attr($redirect_uri) . '" id="redirect_uri" class="regular-text"></td></tr>';
     echo '</table>';
     echo '<p class="submitbox">';
     echo '<input type="submit" name="submit" value="' . __('Save Changes', 'keyring') . '" id="submit" class="button-primary">';
     echo '<a href="' . esc_url($_SERVER['HTTP_REFERER']) . '" class="submitdelete" style="margin-left:2em;">' . __('Cancel', 'keyring') . '</a>';
     echo '</p>';
     echo '</form>';
     echo '</div>';
 }
Пример #9
0
 function column_actions($row)
 {
     $kr_delete_nonce = wp_create_nonce('keyring-delete');
     $delete_nonce = wp_create_nonce('keyring-delete-' . $row->get_service()->get_name() . '-' . $row->get_uniq_id());
     $kr_test_nonce = wp_create_nonce('keyring-test');
     $test_nonce = wp_create_nonce('keyring-test-' . $row->get_service()->get_name() . '-' . $row->get_uniq_id());
     echo '<span class="row-actions">';
     echo '<span class="trash"><a href="' . Keyring_Util::admin_url(false, array('action' => 'delete', 'service' => $row->get_service()->get_name(), 'token' => $row->get_uniq_id(), 'kr_nonce' => $kr_delete_nonce, 'nonce' => $delete_nonce)) . '" title="' . esc_attr(__('Delete', 'keyring')) . '" class="delete">Delete</a></span>';
     echo ' | ';
     echo '<a href="' . Keyring_Util::admin_url(false, array('action' => 'test', 'service' => $row->get_service()->get_name(), 'token' => $row->get_uniq_id(), 'kr_nonce' => $kr_test_nonce, 'nonce' => $test_nonce)) . '" title="' . esc_attr(__('Test', 'keyring')) . '" class="test">Test</a>';
     echo '</span>';
 }
Пример #10
0
 function verify_token()
 {
     if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'keyring-verify-' . $this->get_name())) {
         Keyring::error(__('Invalid/missing verification nonce.', 'keyring'));
         exit;
     }
     // Load up the request token that got us here and globalize it
     if (isset($_REQUEST['state'])) {
         global $keyring_request_token;
         $state = preg_replace('/[^\\x20-\\x7E]/', '', $_GET['state']);
         $keyring_request_token = $this->store->get_token(array('id' => $state, 'type' => 'request'));
         Keyring_Util::debug('HTTP Basic Loaded Request Token ' . $state);
         Keyring_Util::debug($keyring_request_token);
         // Remove request token, don't need it any more.
         $this->store->delete(array('id' => $state, 'type' => 'request'));
     }
     if (!strlen($_POST['username'])) {
         $url = Keyring_Util::admin_url($this->get_name(), array('action' => 'request', 'error' => 'empty', 'kr_nonce' => wp_create_nonce('keyring-request')));
         Keyring_Util::debug($url);
         wp_safe_redirect($url);
         exit;
     }
     // HTTP Basic does not use Keyring_Request_Tokens, since there's only one step
     $token = new Keyring_Access_Token($this->get_name(), base64_encode($_POST['username'] . ':' . $_POST['password']));
     $this->set_token($token);
     $res = $this->request($this->verify_url, array('method' => $this->verify_method));
     // We will get a 401 if they entered an incorrect user/pass combo. ::request
     // will then return a Keyring_Error
     if (Keyring_Util::is_error($res)) {
         $url = Keyring_Util::admin_url($this->get_name(), array('action' => 'request', 'error' => '401', 'kr_nonce' => wp_create_nonce('keyring-request')));
         Keyring_Util::debug($url);
         wp_safe_redirect($url);
         exit;
     }
     $meta = array_merge(array('username' => $_POST['username']), $this->build_token_meta($token));
     $access_token = new Keyring_Access_Token($this->get_name(), $token, $meta);
     $access_token = apply_filters('keyring_access_token', $access_token, array());
     // If we didn't get a 401, then we'll assume it's OK
     $id = $this->store_token($access_token);
     $this->verified($id, $keyring_request_token);
 }
Пример #11
0
 function basic_ui_intro()
 {
     echo '<p>' . sprintf(__('To get started, <a href="%1$s">register an OAuth client on Eventbrite</a>. The most important setting is the <strong>OAuth Redirect URI</strong>, which should be set to <code>%2$s</code>. You can set the other values to whatever you like.', 'keyring'), 'https://www.eventbrite.com/myaccount/apps/', Keyring_Util::admin_url('eventbrite', array('action' => 'verify'))) . '</p>';
     echo '<p>' . __("Once you've saved those changes, copy the <strong>CLIENT/APPLICATION KEY</strong> value into the <strong>API Key</strong> field, and the <strong>CLIENT SECRET</strong> value into the <strong>API Secret</strong> field and click save.", 'keyring') . '</p>';
 }
Пример #12
0
 /**
  * See __construct() for details on how this is hooked in to handle the UI for
  * during the verify process.
  */
 function verify_ui()
 {
     Keyring::admin_page_header();
     echo '<p>As an example, we just randomly generated a token and saved it in the token store. When you go back to your Connections listing, you should see it listed there under "Example Service".</p>';
     echo '<p><a href="' . esc_url(Keyring_Util::admin_url()) . '" class="button-primary">' . __('Done', 'keyring') . '</a>';
     Keyring::admin_page_footer();
 }
    /**
     * The first screen the user sees in the import process. Summarizes the process and allows
     * them to either select an existing Keyring token or start the process of creating a new one.
     * Also makes sure they have the correct service available, and that it's configured correctly.
     */
    function greet()
    {
        if (method_exists($this, 'full_custom_greet')) {
            $this->full_custom_greet();
            return;
        }
        $this->header();
        // If this service is not configured, then we can't continue
        if (!($service = Keyring::get_service_by_name(static::SLUG))) {
            ?>
			<p class="error"><?php 
            echo esc_html(sprintf(__("It looks like you don't have the %s service for Keyring installed.", 'keyring'), static::LABEL));
            ?>
</p>
			<?php 
            $this->footer();
            return;
            ?>
		<?php 
        } elseif (!$service->is_configured()) {
            ?>
			<p class="error"><?php 
            echo esc_html(sprintf(__("Before you can use this importer, you need to configure the %s service within Keyring.", 'keyring'), static::LABEL));
            ?>
</p>
			<?php 
            if (current_user_can('read') && !KEYRING__HEADLESS_MODE && has_action('keyring_' . static::SLUG . '_manage_ui')) {
                $manage_kr_nonce = wp_create_nonce('keyring-manage');
                $manage_nonce = wp_create_nonce('keyring-manage-' . static::SLUG);
                echo '<p><a href="' . esc_url(Keyring_Util::admin_url(static::SLUG, array('action' => 'manage', 'kr_nonce' => $manage_kr_nonce, 'nonce' => $manage_nonce))) . '" class="button-primary">' . sprintf(__('Configure %s Service', 'keyring'), static::LABEL) . '</a></p>';
            }
            $this->footer();
            return;
            ?>
		<?php 
        }
        ?>
		<div class="narrow">
			<form action="admin.php?import=<?php 
        echo static::SLUG;
        ?>
&amp;step=greet" method="post">
				<p><?php 
        printf(__("Howdy! This importer requires you to connect to %s before you can continue.", 'keyring'), static::LABEL);
        ?>
</p>
				<?php 
        do_action('keyring_importer_' . static::SLUG . '_greet');
        ?>
				<?php 
        if ($service->is_connected()) {
            ?>
					<p><?php 
            echo sprintf(esc_html(__('It looks like you\'re already connected to %1$s via %2$s. You may use an existing connection, or create a new one:', 'keyring')), static::LABEL, '<a href="' . esc_attr(Keyring_Util::admin_url()) . '">Keyring</a>');
            ?>
</p>
					<?php 
            $service->token_select_box(static::SLUG . '_token', true);
            ?>
					<input type="submit" name="connect_existing" value="<?php 
            echo esc_attr(__('Continue&hellip;', 'keyring'));
            ?>
" id="connect_existing" class="button-primary" />
				<?php 
        } else {
            ?>
					<p><?php 
            echo esc_html(sprintf(__("To get started, we'll need to connect to your %s account so that we can access your content.", 'keyring'), static::LABEL));
            ?>
</p>
					<input type="submit" name="create_new" value="<?php 
            echo esc_attr(sprintf(__('Connect to %s&#0133;', 'keyring'), static::LABEL));
            ?>
" id="create_new" class="button-primary" />
				<?php 
        }
        ?>
			</form>
		</div>
		<?php 
        $this->footer();
    }
 /**
  * Provides some direction to the user about how to configure the Spotify app
  */
 function basic_ui_intro()
 {
     echo '<p>' . sprintf(__('To get started, <a href="%1$s">register an OAuth client on Spotify</a>. The most important setting is the <strong>Redirect URIs</strong>, which should be set to <code>%2$s</code>. You can set the other values to whatever you like.', 'keyring'), 'https://developer.spotify.com/my-applications/', Keyring_Util::admin_url('spotify', array('action' => 'verify'))) . '</p>';
     echo '<p>' . __("Once you've saved those changes, copy the <strong>CLIENT ID</strong> value into the <strong>API Key</strong> field, and the <strong>CLIENT SECRET</strong> value into the <strong>API Secret</strong> field and click save.", 'keyring') . '</p>';
 }
Пример #15
0
 function basic_ui_intro()
 {
     echo '<p>' . sprintf(__('To get started, <a href="%1$s">register an application with Tumblr</a>. The <strong>Default callback URL</strong> should be set to <code>%2$s</code>, and you can enter whatever you like in the other fields.', 'keyring'), 'http://www.tumblr.com/oauth/register', Keyring_Util::admin_url('tumblr', array('action' => 'verify'))) . '</p>';
     echo '<p>' . __("Once you've created your app, copy the <strong>OAuth Consumer Key</strong> into the <strong>API Key</strong> field below. Click the <strong>Show secret key</strong> link, and then copy the <strong>Secret Key</strong> value into the <strong>API Secret</strong> field below. You don't need an App ID value for Tumblr.", 'keyring') . '</p>';
 }
Пример #16
0
 function verify_token()
 {
     if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'keyring-verify-' . $this->get_name())) {
         Keyring::error(__('Invalid/missing verification nonce.', 'keyring'));
         exit;
     }
     // Load up the request token that got us here and globalize it
     if ($_REQUEST['state']) {
         global $keyring_request_token;
         $state = (int) $_REQUEST['state'];
         $keyring_request_token = $this->store->get_token(array('id' => $state, 'type' => 'request'));
         Keyring_Util::debug('xAuth/Instapaper Loaded Request Token ' . $_REQUEST['state']);
         Keyring_Util::debug($keyring_request_token);
         // Remove request token, don't need it any more.
         $this->store->delete(array('id' => $state, 'type' => 'request'));
     }
     if (!strlen($_POST['username'])) {
         $url = Keyring_Util::admin_url($this->get_name(), array('action' => 'request', 'error' => 'empty', 'kr_nonce' => wp_create_nonce('keyring-request')));
         Keyring_Util::debug($url);
         wp_safe_redirect($url);
         exit;
     }
     $body = array('x_auth_mode' => 'client_auth', 'x_auth_password' => $_POST['password'], 'x_auth_username' => $_POST['username']);
     ksort($body);
     $this->set_token(new Keyring_Access_Token($this->get_name(), null, array()));
     $res = $this->request($this->access_token_url, array('method' => $this->access_token_method, 'raw_response' => true, 'body' => $body));
     Keyring_Util::debug('OAuth1 Access Token Response');
     Keyring_Util::debug($res);
     // We will get a 401 if they entered an incorrect user/pass combo. ::request
     // will then return a Keyring_Error
     if (Keyring_Util::is_error($res)) {
         $url = Keyring_Util::admin_url($this->get_name(), array('action' => 'request', 'error' => '401', 'kr_nonce' => wp_create_nonce('keyring-request')));
         Keyring_Util::debug($url);
         wp_safe_redirect($url);
         exit;
     }
     parse_str($res, $token);
     $meta = array_merge(array('username' => $_POST['username']), $this->build_token_meta($token));
     $access_token = new Keyring_Access_Token($this->get_name(), new OAuthToken($token['oauth_token'], $token['oauth_token_secret']), $meta);
     $access_token = apply_filters('keyring_access_token', $access_token);
     // If we didn't get a 401, then we'll assume it's OK
     $id = $this->store_token($access_token);
     $this->verified($id, $keyring_request_token);
 }
Пример #17
0
 function basic_ui_intro()
 {
     echo '<p>' . sprintf(__("To get started, <a href='https://www.eventbrite.com/api/key'>register an OAuth client on Eventbrite</a>. The most important setting is the <strong>OAuth redirect_uri</strong>, which should be set to <code>%s</code>. You can set the other values to whatever you like.", 'keyring'), esc_url(Keyring_Util::admin_url('eventbrite', array('action' => 'verify')))) . '</p>';
     echo '<p>' . __("Once you've saved those changes, copy the <strong>APPLICATION KEY</strong> value into the <strong>API Key</strong> field, then click the 'Show' link next to the <strong>OAuth client secret</strong>, copy the value into the <strong>API Secret</strong> field and click save (you don't need an App ID value for Eventbrite).", 'keyring') . '</p>';
 }