diff --git a/includes/RestApi/AISearchController.php b/includes/RestApi/AISearchController.php index 72c375d..0409534 100644 --- a/includes/RestApi/AISearchController.php +++ b/includes/RestApi/AISearchController.php @@ -105,7 +105,17 @@ public function get_search_result( \WP_REST_Request $request ) { * @returns \WP_REST_Response|\WP_Error */ public function get_default_search_results( \WP_REST_Request $request ) { - $response = AISearchUtil::get_default_search_results(); + $hiive_token = HiiveConnection::get_auth_token(); + + if ( ! $hiive_token ) { + return new \WP_Error( + 'rest_forbidden', + __( 'You are not authorized to make this call' ), + array( 'status' => 403 ) + ); + } + + $response = AISearchUtil::get_default_search_results( $hiive_token ); if ( array_key_exists( 'error', $response ) ) { return new \WP_Error( 'ServerError', $response['error'] ); diff --git a/includes/Utils/AISearchUtil.php b/includes/Utils/AISearchUtil.php index a074e8c..18f2a53 100644 --- a/includes/Utils/AISearchUtil.php +++ b/includes/Utils/AISearchUtil.php @@ -93,9 +93,10 @@ public static function get_search_results( /** * The function to get the default results from the proxy * + * @param string $hiive_token The Hive token * @return array */ - public static function get_default_search_results() { + public static function get_default_search_results( $hiive_token ) { if (!self::_check_help_capability()) { return array( 'error' => __('We are unable to process the request at this moment'), @@ -103,13 +104,18 @@ public static function get_default_search_results() { } $response = wp_remote_post( - NFD_AI_SERVICE_BASE, + NFD_AI_SERVICE_BASE . 'defaultResults', array( 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/json', ), 'timeout' => 60, + 'body' => wp_json_encode( + array( + 'hiivetoken' => $hiive_token, + ) + ), ) ); if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {