WC_API_Authentication::perform_oauth_authentication()
Perform OAuth 1.0a "one-legged" (http://oauthbible.com/#oauth-10a-one-legged) authentication for non-SSL requests
This is required so API credentials cannot be sniffed or intercepted when making API requests over plain HTTP
This follows the spec for simple OAuth 1.0a authentication (RFC 5849) as closely as possible, with two exceptions:
1) There is no token associated with request/responses, only consumer keys/secrets are used
2) The OAuth parameters are included as part of the request query string instead of part of the Authorization header,
This is because there is no cross-OS function within PHP to get the raw Authorization header
Method of the class: WC_API_Authentication{}
No Hooks.
Return
Array
.
Usage
// private - for code of main (parent) class only $result = $this->perform_oauth_authentication();
Changelog
Since 2.1 | Introduced. |
WC_API_Authentication::perform_oauth_authentication() WC API Authentication::perform oauth authentication code WC 7.7.0
private function perform_oauth_authentication() { $params = WC()->api->server->params['GET']; $param_names = array( 'oauth_consumer_key', 'oauth_timestamp', 'oauth_nonce', 'oauth_signature', 'oauth_signature_method' ); // Check for required OAuth parameters foreach ( $param_names as $param_name ) { if ( empty( $params[ $param_name ] ) ) { /* translators: %s: parameter name */ throw new Exception( sprintf( __( '%s parameter is missing', 'woocommerce' ), $param_name ), 404 ); } } // Fetch WP user by consumer key $keys = $this->get_keys_by_consumer_key( $params['oauth_consumer_key'] ); // Perform OAuth validation $this->check_oauth_signature( $keys, $params ); $this->check_oauth_timestamp_and_nonce( $keys, $params['oauth_timestamp'], $params['oauth_nonce'] ); // Authentication successful, return user return $keys; }