rest api – WordPress custom API with WooCommerce Authentication

Question

I have created custom API in WordPress and I am getting WooCommerce Subscription data in this API and its working fine as per my requirements.

Howerver, now I want to add basic authentication in this API which can check consumer key and secret like other WooCommerce API endpoints.

This is my sample API looks like in which I want to check basic authentication.

// Action to execute Rest API routes
add_action('rest_api_init', function () {

    // Getting Product data based on subscription id
    register_rest_route('getproductdata', '/(?P<id>d+)', array(
        'methods' => 'GET',
        'callback' => 'getProductData',
    ));
});


function getProductData($request) {
    // I WANT TO CHECK BASIC AUTHENTICATION HERE BEFORE EXECUTING BELOW CODE 


    die('inside my api');
}

I have checked this https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication-over-http and How to authenticate custom API endpoint in WooCommerce this urls but I have not found yet proper method or filter or tutorial yet to accomplish my requirements.

Can someone at-least guide me how can I add authentication here .. any suggestion will be highly appreciated.

Thanks

0
Mittul At TechnoBrave 2 years 2021-03-21T23:29:50-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse