auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* WC_Helper_API Class
*
* Provides a communication interface with the Woo.com Helper API.
* Provides a communication interface with the WooCommerce.com Helper API.
*/
class WC_Helper_API {
/**
@@ -67,6 +67,61 @@ class WC_Helper_API {
return wp_safe_remote_request( $url, $args );
}
/**
* Create signature for a request.
*
* @param string $access_token_secret The access token secret.
* @param string $url The URL to add the access token and signature to.
* @param string $method The request method.
* @param array $body The body of the request.
* @return string The signature.
*/
private static function create_request_signature( string $access_token_secret, string $url, string $method, $body = null ): string {
$request_uri = wp_parse_url( $url, PHP_URL_PATH );
$query_string = wp_parse_url( $url, PHP_URL_QUERY );
if ( is_string( $query_string ) ) {
$request_uri .= '?' . $query_string;
}
$data = array(
'host' => wp_parse_url( $url, PHP_URL_HOST ),
'request_uri' => $request_uri,
'method' => $method,
);
if ( ! empty( $body ) ) {
$data['body'] = $body;
}
return hash_hmac( 'sha256', wp_json_encode( $data ), $access_token_secret );
}
/**
* Add the access token and signature to the provided URL.
*
* @param string $url The URL to add the access token and signature to.
* @return string
*/
public static function add_auth_parameters( string $url ): string {
$auth = WC_Helper_Options::get( 'auth' );
if ( empty( $auth['access_token'] ) || empty( $auth['access_token_secret'] ) ) {
return false;
}
$signature = self::create_request_signature( (string) $auth['access_token_secret'], $url, 'GET' );
return add_query_arg(
array(
'token' => $auth['access_token'],
'signature' => $signature,
),
$url
);
}
/**
* Adds authentication headers to an HTTP request.
*
@@ -81,24 +136,13 @@ class WC_Helper_API {
return false;
}
$request_uri = parse_url( $url, PHP_URL_PATH );
$query_string = parse_url( $url, PHP_URL_QUERY );
if ( is_string( $query_string ) ) {
$request_uri .= '?' . $query_string;
}
$data = array(
'host' => parse_url( $url, PHP_URL_HOST ),
'request_uri' => $request_uri,
'method' => ! empty( $args['method'] ) ? $args['method'] : 'GET',
$signature = self::create_request_signature(
(string) $auth['access_token_secret'],
$url,
! empty( $args['method'] ) ? $args['method'] : 'GET',
$args['body'] ?? null
);
if ( ! empty( $args['body'] ) ) {
$data['body'] = $args['body'];
}
$signature = hash_hmac( 'sha256', json_encode( $data ), $auth['access_token_secret'] );
if ( empty( $args['headers'] ) ) {
$args['headers'] = array();
}