WC_API_Authentication::exit_with_unauthorized_headers()privateWC 2.4

If the consumer_key and consumer_secret $_GET parameters are NOT provided and the Basic auth headers are either not present or the consumer secret does not match the consumer key provided, then return the correct Basic headers and an error message.

Method of the class: WC_API_Authentication{}

No Hooks.


null. Nothing (null).


// private - for code of main (parent) class only
$result = $this->exit_with_unauthorized_headers();


Since 2.4 Introduced.

WC_API_Authentication::exit_with_unauthorized_headers() code WC 8.7.0

private function exit_with_unauthorized_headers() {
	$auth_message = __( 'WooCommerce API. Use a consumer key in the username field and a consumer secret in the password field.', 'woocommerce' );
	header( 'WWW-Authenticate: Basic realm="' . $auth_message . '"' );
	header( 'HTTP/1.0 401 Unauthorized' );
	throw new Exception( __( 'Consumer Secret is invalid.', 'woocommerce' ), 401 );