Automattic\WooCommerce\Internal\PushNotifications\Controllers

PushTokenRestController::authorize_as_from_wpcompublicWC 10.8.0

Validates that the request is signed with a Jetpack blog token, ensuring only WPCOM can access this endpoint.

Method of the class: PushTokenRestController{}

No Hooks.

Returns

true|false|WP_Error.

Usage

$PushTokenRestController = new PushTokenRestController();
$PushTokenRestController->authorize_as_from_wpcom( $request );
$request(WP_REST_Request) (required)
The request object.

Changelog

Since 10.8.0 Introduced.

PushTokenRestController::authorize_as_from_wpcom() code WC 11.0.1

public function authorize_as_from_wpcom( WP_REST_Request $request ) {
	if ( ! wc_get_container()->get( PushNotifications::class )->should_be_enabled() ) {
		return false;
	}

	if (
		class_exists( Rest_Authentication::class )
		&& Rest_Authentication::is_signed_with_blog_token()
	) {
		return true;
	}

	return new WP_Error(
		'woocommerce_rest_cannot_view',
		__( 'Sorry, you are not allowed to do that.', 'woocommerce' ),
		array( 'status' => rest_authorization_required_code() )
	);
}