WC_Helper_API::_authenticate
Adds authentication headers to an HTTP request.
Method of the class: WC_Helper_API{}
No Hooks.
Returns
true|false. Were the headers added?
Usage
$result = WC_Helper_API::_authenticate( $url, $args );
- $url(string) (required) (passed by reference — &)
- The request URI.
- $args(array) (required) (passed by reference — &)
- By-ref, the args that will be passed to wp_remote_request().
WC_Helper_API::_authenticate() WC Helper API:: authenticate code WC 10.3.3
private static function _authenticate( &$url, &$args ) {
$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,
! empty( $args['method'] ) ? $args['method'] : 'GET',
$args['body'] ?? null
);
if ( empty( $args['headers'] ) ) {
$args['headers'] = array();
}
$headers = array(
'Authorization' => 'Bearer ' . $auth['access_token'],
'X-Woo-Signature' => $signature,
);
$args['headers'] = wp_parse_args( $headers, $args['headers'] );
$url = add_query_arg(
array(
'token' => $auth['access_token'],
'signature' => $signature,
),
$url
);
return true;
}