/**
  * Exchange the request token for an access token
  *
  * Endpoint: /auth/access_token
  */
 public static function access_token()
 {
     try {
         $request = OAuthRequest::from_request();
         $result = WPOAuthProvider::access_token($request);
         header('Content-Type: application/x-www-form-urlencoded');
         echo $result;
     } catch (OAuthException $e) {
         throw new Exception($e->getMessage(), 401);
     }
 }
Esempio n. 2
0
    /**
     * OAuth configuration page
     *
     * Hooked via `add_dashboard_page()`
     * @see menu()
     * @param WP_User $user Current user
     */
    public static function oauth_config($user)
    {
        #delete_option('wpoa_consumers');
        if (!empty($_POST['action'])) {
            if ($_POST['action'] === 'create') {
                check_admin_referer('wpoa_create_consumer', 'wpoa_nonce');
                $name = $description = '';
                if (!empty($_POST['consumer_name'])) {
                    $name = stripslashes($_POST['consumer_name']);
                }
                if (!empty($_POST['consumer_desc'])) {
                    $description = stripslashes($_POST['consumer_desc']);
                }
                $key = WPOAuthProvider::create_consumer($name, $description);
            } elseif ($_POST['action'] === 'delete' && !empty($_POST['key'])) {
                check_admin_referer('wpoa_delete_consumer', 'wpoa_nonce');
                WPOAuthProvider::delete_consumer($_POST['key']);
            }
        }
        $consumers = self::$data->get_consumers();
        ?>
	<h2><?php 
        _e('OAuth Details', 'wpoaprovider');
        ?>
</h2>
<?php 
        ?>
	<table class="widefat">
		<thead>
			<tr>
				<th>Name</th>
				<th>Description</th>
				<th>Key</th>
				<th>Secret</th>
				<th>Action</th>
			</tr>
		</head>
		<tbody>
<?php 
        if (!empty($consumers)) {
            foreach ($consumers as $key => $consumer) {
                ?>
			<tr>
				<td><?php 
                echo $consumer->name;
                ?>
</td>
				<td><?php 
                echo $consumer->description;
                ?>
</td>
				<td><code><?php 
                echo $consumer->key;
                ?>
</code></td>
				<td><code><?php 
                echo $consumer->secret;
                ?>
</code></td>
				<td>
					<form action="" method="POST">
						<?php 
                wp_nonce_field('wpoa_delete_consumer', 'wpoa_nonce');
                ?>
						<input type="hidden" name="action" value="delete" />
						<input type="hidden" name="key" value="<?php 
                echo esc_attr($consumer->key);
                ?>
" />
						<input type="submit"
							class="button button-small"
							value="<?php 
                esc_attr_e('Delete', 'wpoaprovider');
                ?>
" />
					</form>
				</td>
			</tr>
<?php 
            }
        } else {
            ?>
			<tr>
				<td colspan="5"><?php 
            _e('No consumers found.', 'wpoaprovider');
            ?>
</td>
			</tr>
<?php 
        }
        ?>
		</tbody>
	</table>

	<form action="" method="POST">
		<h3><?php 
        _e('Add New Consumer', 'wpoaprovider');
        ?>
</h3>
		<table class="form-table">
			<tr>
				<th scope="row"><label for="wpoa_consumer_name"><?php 
        _ex('Name', 'form label', 'wpoaprovider');
        ?>
</label></th>
				<td><input type="text" class="regular-text" name="consumer_name" id="wpoa_consumer_name" /></td>
			</tr>
			<tr>
				<th scope="row"><label for="wpoa_consumer_desc"><?php 
        _ex('Description', 'form label', 'wpoaprovider');
        ?>
</label></th>
				<td><input type="text" class="regular-text" name="consumer_desc" id="wpoa_consumer_desc" /></td>
			</tr>
		</table>

		<?php 
        wp_nonce_field('wpoa_create_consumer', 'wpoa_nonce');
        ?>
		<input type="hidden" name="action" value="create" />
		<p class="submit"><input type="submit" class="button button-primary" value="<?php 
        esc_attr_e('Add Consumer', 'wpoaprovider');
        ?>
" /></p>
	</form>
<?php 
    }