Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from WP-API/rename-file
Browse files Browse the repository at this point in the history
Split out files
  • Loading branch information
rmccue authored Oct 6, 2016
2 parents 575d475 + 1eb270a commit 010669c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
50 changes: 4 additions & 46 deletions centraliser.php → inc/class-wp-rest-authbroker.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
<?php
/**
* Plugin Name: WP REST API Authentication Broker
* Description: Allow bootstrapping site authentication via a central registry.
*/

add_action( 'rest_api_init', 'rest_broker_register_routes' );

function rest_broker_register_routes() {
if ( empty( $GLOBALS['wp_json_authentication_oauth1'] ) ) {
// OAuth must be enabled for the broker to actually do anything
return;
}

$broker = new WP_REST_AuthBroker();

register_rest_route( 'broker/v1', '/connect', array(
array(
'methods' => 'GET',
'callback' => array( $broker, 'get_connect_information' ),
),
array(
'methods' => 'POST',
'callback' => array( $broker, 'handle_connect' ),
'args' => array(
'client_id' => array(
'required' => true,
),
'broker' => array(
'required' => true,
),
'verifier' => array(
'required' => true,
),
'client_name' => array(),
'client_description' => array(),
'client_details' => array(),
),
),
));

add_action( 'rest_index', array( $broker, 'add_index_link' ) );
}

class WP_REST_AuthBroker {
protected $data;
Expand Down Expand Up @@ -68,8 +26,8 @@ public function add_index_link( WP_REST_Response $index ) {

public function get_connect_information( WP_REST_Request $request ) {
$response = new WP_REST_Response();
$response->set_data('This endpoint is used for the Brokered Authentication protocol.');
$response->header('X-BA-Endpoint', 'connection-request');
$response->set_data( 'This endpoint is used for the Brokered Authentication protocol.' );
$response->header( 'X-BA-Endpoint', 'connection-request' );
return $response;
}

Expand Down Expand Up @@ -174,11 +132,11 @@ public function issue_and_verify() {

// Verified, time to create the client.
$client_params = array(
'key' => $key,
'secret' => $secret,
'name' => $this->data['client_name'] ? $this->data['client_name'] : 'Unknown',
'description' => $this->data['client_description'] ? $this->data['client_description'] : 'Unknown',
'meta' => array(
'key' => $key,
'secret' => $secret,
'callback' => $this->data['callback'],
'broker_id' => $this->data['broker'],
'broker_client_id' => $this->data['client'],
Expand Down
47 changes: 47 additions & 0 deletions plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Plugin Name: WP REST API Authentication Broker
* Description: Allow bootstrapping site authentication via a Broker Registry.
* Version: 0.1.0
* Author: WP REST API Team
* Author URI: http://wp-api.org/
*/

add_action( 'rest_api_init', 'rest_broker_register_routes' );

function rest_broker_register_routes() {
if ( empty( $GLOBALS['wp_json_authentication_oauth1'] ) ) {
// OAuth must be enabled for the broker to actually do anything
return;
}
require_once( dirname( __FILE__ ) . '/inc/class-wp-rest-authbroker.php' );

$broker = new WP_REST_AuthBroker();

register_rest_route( 'broker/v1', '/connect', array(
array(
'methods' => 'GET',
'callback' => array( $broker, 'get_connect_information' ),
),
array(
'methods' => 'POST',
'callback' => array( $broker, 'handle_connect' ),
'args' => array(
'client_id' => array(
'required' => true,
),
'broker' => array(
'required' => true,
),
'verifier' => array(
'required' => true,
),
'client_name' => array(),
'client_description' => array(),
'client_details' => array(),
),
),
));

add_action( 'rest_index', array( $broker, 'add_index_link' ) );
}

0 comments on commit 010669c

Please sign in to comment.