PHP Class WDS_WP_REST_API\OAuth1\Connect

API Documentation https://github.com/WP-API/WP-API/tree/master/docs OAuth Authentication API https://github.com/WP-API/OAuth1/blob/master/docs/spec.md The OAuth 1.0 Protocol http://tools.ietf.org/html/rfc5849
Author: Justin Sternberg ([email protected])
ファイルを表示 Open project: webdevstudios/wds-wp-rest-api-connect Class Usage Examples

Public Properties

Property Type Description
$json_desc
$response
$response_code

Protected Properties

Property Type Description
$access_token
$access_token_secret
$api_url
$autoredirect_authoriziation
$callback_uri
$client_key
$client_secret
$endpoint_url
$headers
$is_authorizing
$key
$method
$server WPServer OAuth1 Client
$store WDS_WP_REST_API\Storage\Store_Interface Options Store
$transient WDS_WP_REST_API\Storage\Transient_Interface Transients Store

Public Methods

Method Description
__construct ( array $storage_classes = [] ) Connect object constructor.
__get ( string $field ) : mixed Magic getter for our object.
api_url ( string $path = '' ) : string Get the api_url and append included path
args ( ) : array Get current object data for debugging.
auth_delete_request ( string $path, $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated DELETE request
auth_get_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated GET request
auth_head_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated HEAD request
auth_post_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error Perform an authenticated POST request
auth_request ( string $path, array $request_args = [], string $method = 'GET' ) : object | WP_Erro\WP_Error Perform an authenticated request
cache_api_description_for_api_url ( ) : mixed Fetches and caches the API Description object
connected ( ) : boolean Tests whether connection has been created.
delete_option ( $option = '' ) : boolean Handles deleting the stored data for a connection
delete_stored_error ( ) : mixed Fetches the wp_rest_api_connect_error option value
discovered ( ) : boolean Tests whether API discovery has been completed.
do_authorization ( string $oauth_token, string $oauth_verifier ) : mixed Swap temporary credentials for permanent authorized credentials.
do_discovery ( string $url = '' ) : string | WP_Erro\WP_Error Do the API discovery.
get_api_description ( ) : object Retrieves the API Description object
get_authorization_url ( ) : string | WP_Erro\WP_Error Get the authorization (login) URL for the server.
get_json_if_json ( string $body ) : mixed Determines if a string is JSON, and if so, decodes it and returns it. Else returns unchanged body object.
get_option ( string $option = 'all' ) : mixed Retrieve stored option
get_requested_url ( ) : string Get the current URL
get_server ( ) : WPServer Get WPServer object
get_stored_error ( ) : mixed Fetches the wp_rest_api_connect_error option value.
get_stored_error_message ( ) : string Fetches the wp_rest_api_connect_error message.
get_stored_error_request_args ( ) : string Fetches the wp_rest_api_connect_error request_args.
get_stored_error_request_response ( ) : string Fetches the wp_rest_api_connect_error request_response.
get_user ( ) : mixed Get's authorized user. Useful for testing authenticated connection.
init ( array $args ) Initate our connect object
is_authorizing ( ) : boolean Check if the authorization callback has been initiated.
is_json ( string $string ) : boolean | array Determines if a string is JSON, and if so, decodes it.
key ( ) : string Get the stored-data key
maybe_redirect_to_authorization ( ) : boolean | WP_Erro\WP_Error If autoredirect is enabled, and we are not yet authorized, redirect to the server to get authorization.
redirect_to_login ( ) : mixed Do the redirect to the authorization (login) URL.
request_access_url ( ) : mixed Gets the access URL from the JSON description object
request_authorize_url ( ) : mixed Gets the authorization base URL from the JSON description object
request_token_url ( ) : mixed Gets the request URL from the JSON description object
reset_connection ( ) Deletes all stored data for this connection.
set_api_url ( string $value ) Sets the api_url object property
set_callback_uri ( string $value ) Sets the callback_uri object property
set_client_key ( string $value ) Sets the client_key object property
set_client_secret ( string $value ) Sets the client_secret object property
set_endpoint_url ( string $value ) Sets the endpoint_url object property
set_headers ( $headers ) Sets the headers object property
set_method ( string $method ) : string Set request method
set_object_properties ( ) Get the options from the DB and set the object properties.
update_option ( string $option, mixed $value, boolean $set = true ) : Original Update the options array
update_stored_error ( string $error = '' ) : void Updates/replaces the wp_rest_api_connect_error option.

Protected Methods

Method Description
instantiate_storage_objects ( WDS_WP_REST_API\Storage\Store_Interface $store, WDS_WP_REST_API\Storage\Store_Interface $error_store, WDS_WP_REST_API\Storage\Transient_Interface $transient ) Instantiates the storage objects for the options and transients.

Method Details

__construct() public method

Connect object constructor.
Since: 0.2.0
public __construct ( array $storage_classes = [] )
$storage_classes array (optional) override the storage classes.

__get() public method

Magic getter for our object.
public __get ( string $field ) : mixed
$field string
return mixed

api_url() public method

Get the api_url and append included path
Since: 0.1.0
public api_url ( string $path = '' ) : string
$path string Option path to append
return string REST request URL

args() public method

Get current object data for debugging.
Since: 0.2.0
public args ( ) : array
return array

auth_delete_request() public method

Perform an authenticated DELETE request
Since: 0.1.0
public auth_delete_request ( string $path, $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
return object | WP_Erro\WP_Error Updated object, or WP_Error

auth_get_request() public method

Perform an authenticated GET request
Since: 0.1.0
public auth_get_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$data array Array of data to send in request.
return object | WP_Erro\WP_Error Updated object, or WP_Error

auth_head_request() public method

Perform an authenticated HEAD request
Since: 0.1.0
public auth_head_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$data array Array of data to send in request.
return object | WP_Erro\WP_Error Updated object, or WP_Error

auth_post_request() public method

Perform an authenticated POST request
Since: 0.1.0
public auth_post_request ( string $path, array $data = [] ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$data array Array of data to send in request.
return object | WP_Erro\WP_Error Updated object, or WP_Error

auth_request() public method

Perform an authenticated request
Since: 0.1.0
public auth_request ( string $path, array $request_args = [], string $method = 'GET' ) : object | WP_Erro\WP_Error
$path string Url endpoint path to resource
$request_args array Array of data to send in request.
$method string Request method. Defaults to GET
return object | WP_Erro\WP_Error Updated object, or WP_Error

cache_api_description_for_api_url() public method

Fetches and caches the API Description object
Since: 0.1.0
public cache_api_description_for_api_url ( ) : mixed
return mixed Description object for api_url

connected() public method

Tests whether connection has been created.
Since: 0.2.0
public connected ( ) : boolean
return boolean

delete_option() public method

Handles deleting the stored data for a connection
Since: 0.1.3
public delete_option ( $option = '' ) : boolean
return boolean Result of delete_option

delete_stored_error() public method

Fetches the wp_rest_api_connect_error option value
Since: 0.1.3
public delete_stored_error ( ) : mixed
return mixed wp_rest_api_connect_error option value

discovered() public method

Tests whether API discovery has been completed.
Since: 0.2.0
public discovered ( ) : boolean
return boolean

do_authorization() public method

Swap temporary credentials for permanent authorized credentials.
Since: 0.2.0
public do_authorization ( string $oauth_token, string $oauth_verifier ) : mixed
$oauth_token string
$oauth_verifier string
return mixed WP_Error if failure, else redirect to callback_uri.

do_discovery() public method

Do the API discovery.
Since: 0.2.0
public do_discovery ( string $url = '' ) : string | WP_Erro\WP_Error
$url string The URL to discover.
return string | WP_Erro\WP_Error The API endpoint URL or WP_Error.

get_api_description() public method

Retrieves the API Description object
Since: 0.1.0
public get_api_description ( ) : object
return object Description object for api_url

get_authorization_url() public method

Get the authorization (login) URL for the server.
Since: 0.2.0
public get_authorization_url ( ) : string | WP_Erro\WP_Error
return string | WP_Erro\WP_Error Authorization URL or WP_Error.

get_json_if_json() public method

Determines if a string is JSON, and if so, decodes it and returns it. Else returns unchanged body object.
Since: 0.1.2
public get_json_if_json ( string $body ) : mixed
$body string HTTP retrieved body
return mixed Decoded JSON object or unchanged body

get_option() public method

Retrieve stored option
Since: 0.1.0
public get_option ( string $option = 'all' ) : mixed
$option string Option array key
return mixed Value of option requested

get_requested_url() public method

Get the current URL
Since: 0.2.0
public get_requested_url ( ) : string
return string current URL

get_server() public method

Get WPServer object
Since: 0.2.0
public get_server ( ) : WPServer
return WPServer

get_stored_error() public method

Fetches the wp_rest_api_connect_error option value.
Since: 0.1.3
public get_stored_error ( ) : mixed
return mixed wp_rest_api_connect_error option value.

get_stored_error_message() public method

Fetches the wp_rest_api_connect_error message.
Since: 0.1.3
public get_stored_error_message ( ) : string
return string Stored error message value.

get_stored_error_request_args() public method

Fetches the wp_rest_api_connect_error request_args.
Since: 0.1.3
public get_stored_error_request_args ( ) : string
return string Stored error request_args value.

get_stored_error_request_response() public method

Fetches the wp_rest_api_connect_error request_response.
Since: 0.1.3
public get_stored_error_request_response ( ) : string
return string Stored error request_response value.

get_user() public method

Get's authorized user. Useful for testing authenticated connection.
Since: 0.2.0
public get_user ( ) : mixed
return mixed User object or WP_Error object.

init() public method

Initate our connect object
Since: 0.1.0
public init ( array $args )
$args array Arguments containing 'client_key', 'client_secret', 'api_url', 'headers', 'callback_uri', 'autoredirect_authoriziation'

instantiate_storage_objects() protected method

Instantiates the storage objects for the options and transients.
Since: 0.2.0
protected instantiate_storage_objects ( WDS_WP_REST_API\Storage\Store_Interface $store, WDS_WP_REST_API\Storage\Store_Interface $error_store, WDS_WP_REST_API\Storage\Transient_Interface $transient )
$store WDS_WP_REST_API\Storage\Store_Interface Option storage
$error_store WDS_WP_REST_API\Storage\Store_Interface Error option storage
$transient WDS_WP_REST_API\Storage\Transient_Interface Transient storage

is_authorizing() public method

Check if the authorization callback has been initiated.
Since: 0.2.0
public is_authorizing ( ) : boolean
return boolean

is_json() public method

Determines if a string is JSON, and if so, decodes it.
Since: 0.1.0
public is_json ( string $string ) : boolean | array
$string string String to check if is JSON
return boolean | array Decoded JSON object or false

key() public method

Get the stored-data key
Since: 0.2.0
public key ( ) : string
return string

maybe_redirect_to_authorization() public method

If autoredirect is enabled, and we are not yet authorized, redirect to the server to get authorization.
Since: 0.2.0
public maybe_redirect_to_authorization ( ) : boolean | WP_Erro\WP_Error
return boolean | WP_Erro\WP_Error WP_Error is an issue, else redirects.

redirect_to_login() public method

Do the redirect to the authorization (login) URL.
Since: 0.2.0
public redirect_to_login ( ) : mixed
return mixed WP_Error if authorization URL lookup fails.

request_access_url() public method

Gets the access URL from the JSON description object
Since: 0.1.0
public request_access_url ( ) : mixed
return mixed Access URL or error

request_authorize_url() public method

Gets the authorization base URL from the JSON description object
Since: 0.1.0
public request_authorize_url ( ) : mixed
return mixed Authorization URL or error

request_token_url() public method

Gets the request URL from the JSON description object
Since: 0.1.0
public request_token_url ( ) : mixed
return mixed Request URL or error

reset_connection() public method

Deletes all stored data for this connection.
Since: 0.2.0
public reset_connection ( )

set_api_url() public method

Sets the api_url object property
Since: 0.2.0
public set_api_url ( string $value )
$value string Value to set

set_callback_uri() public method

Sets the callback_uri object property
Since: 0.2.0
public set_callback_uri ( string $value )
$value string Value to set

set_client_key() public method

Sets the client_key object property
Since: 0.2.0
public set_client_key ( string $value )
$value string Value to set

set_client_secret() public method

Sets the client_secret object property
Since: 0.2.0
public set_client_secret ( string $value )
$value string Value to set

set_endpoint_url() public method

Sets the endpoint_url object property
Since: 0.2.0
public set_endpoint_url ( string $value )
$value string Value to set

set_headers() public method

Sets the headers object property
Since: 0.2.0
public set_headers ( $headers )

set_method() public method

Set request method
Since: 0.1.1
public set_method ( string $method ) : string
$method string Request method
return string New request method

set_object_properties() public method

Get the options from the DB and set the object properties.
Since: 0.2.0

update_option() public method

Update the options array
Since: 0.1.0
public update_option ( string $option, mixed $value, boolean $set = true ) : Original
$option string Option array key
$value mixed Value to be updated
$set boolean Whether to set the updated value in the DB.
return Original $value if successful

update_stored_error() public method

Updates/replaces the wp_rest_api_connect_error option.
Since: 0.1.3
public update_stored_error ( string $error = '' ) : void
$error string Error message
return void

Property Details

$access_token protected_oe property

protected $access_token

$access_token_secret protected_oe property

protected $access_token_secret

$api_url protected_oe property

protected $api_url

$autoredirect_authoriziation protected_oe property

protected $autoredirect_authoriziation

$callback_uri protected_oe property

protected $callback_uri

$client_key protected_oe property

protected $client_key

$client_secret protected_oe property

protected $client_secret

$endpoint_url protected_oe property

protected $endpoint_url

$headers protected_oe property

protected $headers

$is_authorizing protected_oe property

protected $is_authorizing

$json_desc public_oe property

public $json_desc

$key protected_oe property

protected $key

$method protected_oe property

protected $method

$response public_oe property

public $response

$response_code public_oe property

public $response_code

$server protected_oe property

OAuth1 Client
protected WPServer,WDS_WP_REST_API\OAuth1 $server
return WPServer

$store protected_oe property

Options Store
protected Store_Interface,WDS_WP_REST_API\Storage $store
return WDS_WP_REST_API\Storage\Store_Interface

$transient protected_oe property

Transients Store
protected Transient_Interface,WDS_WP_REST_API\Storage $transient
return WDS_WP_REST_API\Storage\Transient_Interface