• Resolved careerbuggy

    (@careerbuggy)


    I tried to create Whitelisting Endpoints function as mentioned still I get same error saying JWT authorization is not found error.

Viewing 15 replies - 1 through 15 (of 26 total)
  • Thread Starter careerbuggy

    (@careerbuggy)

    could anyone help me in whitelisting the endpoints. it would be a great help.

    Plugin Author Bagus

    (@contactjavas)

    Hi @careerbuggy , sorry i just see your tickets.
    Didn’t understand why new tickets doesn’t directly come to my inbox.

    Could you please paste your whitelisting code here?

    Thanks for your question,
    Bagus

    Hi Mr Bagus,
    I am also facing same issue, white listed routes been authenticated.

    add_filter(‘jwt_auth_whitelist’, function ( $endpoints ) {
    return array(
    ‘/wp-json/wp/v2/*’,
    ‘/wp-json/yoast/v1/*’,
    ‘/wp-json/wpcom/v2/*’,
    ‘/wp-json/wp/v1/*’,
    ‘/wp-json/jetpack/v4/*’
    );
    });

    But still authenticating the whitelisted route. getting following error

    {“success”:false,”statusCode”:403,”code”:”jwt_auth_no_auth_header”,”message”:”Authorization header not found.”,”data”:[]}

    Plugin Author Bagus

    (@contactjavas)

    Hi @giriposhaneshwar , thanks for reporting,
    I’m checking it now, will get back to you asap.

    Bagus

    Plugin Author Bagus

    (@contactjavas)

    Hi @careerbuggy & @giriposhaneshwar , thanks for waiting ??

    I’ve tested it. Here is the result:
    – adding the filter directly (without hook) works
    – adding the filter inside plugins_loaded also works
    – adding the filter inside init didn’t work
    – that means, adding the filter after init hook will also not work.

    Please check your code, did you add the filter inside init hook (or hooks after it)? If so, please change it by adding the filter directly. Or if you want to add it inside hook, please use plugins_loaded instead.

    Please let me know if that works for you ??

    Thanks!
    Bagus

    Hi Mr. Bagus,
    Thanks for quick response.

    Could you please provide the sample working code for my reference.

    Plugin Author Bagus

    (@contactjavas)

    Hi @giriposhaneshwar , this is just your code

    
    add_filter(
    	'jwt_auth_whitelist',
    	function ( $endpoints ) {
    		'/wp-json/wp/v2/*',
    		'/wp-json/yoast/v1/*',
    		'/wp-json/wpcom/v2/*',
    		'/wp-json/wp/v1/*',
    		'/wp-json/jetpack/v4/*',
    	}
    );
    

    Just add it without hook. Or simply put it in your functions.php (if you use theme).
    After that, please also clear your cache if you use GET request.

    Please let me know if that works.
    Thanks,
    Bagus

    Hi Mr. Bagus,
    Thanks helping me out for information.

    – I am using Theme.
    – With in function.php only i am initializing “rest_api_init”
    – Added the “add_filter(‘jwt_auth_whitelist’, function ( $endpoints )” before initializing rest_API_init.
    – but still facing issue.

    Getting above error for while creating blogs from admin panel itself. For custom end point with authentication token working fine with your plugin.

    I am new to WordPress, please guide me in whitelisting the default API / routes which i mentioned in above query.

    Following is the sequence of my code implementation:

    add_filter(‘jwt_auth_whitelist’, function ( $endpoints ) {
    return array(
    ‘/wp-json/wp/v2/*’,
    ‘/wp-json/yoast/v1/*’,
    ‘/wp-json/wpcom/v2/*’,
    ‘/wp-json/wp/v1/*’,
    ‘/wp-json/jetpack/v4/*’
    );
    });

    /*
    * Creating Custom End POint
    * API )
    */

    add_action(‘rest_api_init’, function () {
    register_rest_route(‘wp/v1’, ‘allposts’, array(
    ‘methods’ => ‘GET’,
    ‘callback’ => ‘get_latest_post’
    ));
    register_rest_route(‘wp/v1’, ‘getPostByKey’, array(
    ‘methods’ => ‘GET’,
    ‘callback’ => ‘get_post_By_Key’
    ));
    register_rest_route(‘wp/v1’, ‘getThemeBlogs’, array(
    ‘methods’ => ‘GET’,
    ‘callback’ => ‘get_theme_blogs’
    ));
    });

    Plugin Author Bagus

    (@contactjavas)

    Hi @giriposhaneshwar , would you mind to share your files to [email protected] ? Could be FTP or zip file. Would be easier to see your issue more detail ??

    Thanks,
    Bagus

    hello,
    I am having the same issue with whitelist filter not working.

    my functions.php

    add_filter(
    		'jwt_auth_whitelist',
    		'my_endpoints'
    	);
    
    	function my_endpoints($endpoints) {
    		$endpoints[] = '/wp-json/test/';
    		return $endpoints;
    	}

    testing in the plugin file class-auth.php i put a var dump and the whitelist is still empty. some how not applying the filter

    $whitelist = apply_filters( 'jwt_auth_whitelist', array() );
    		var_dump($whitelist);

    i also tried with the jwt_auth_default_whitelist filter, but it didn’t work either.. Any help would be appreciated! thanks!

    Plugin Author Bagus

    (@contactjavas)

    Hi @rozv , I’m testing this filter. I use to put the filter in the plugin. I’ll try this in the theme. Will get back here in minutes.

    Thanks a lot for reporting,
    Bagus

    Plugin Author Bagus

    (@contactjavas)

    Hi @rozv , i’ve tested (by moving the filter from plugin to theme’s functions.php) and it works both on parent & child theme. I need more info from you:

    – What is the full url that is facing this issue? Is it simply this _site.com/wp-json/test/_?
    – You simply put it in functions.php right? without putting it into any hook. (just to make sure)
    – Is it possible for you to provide demo site for me? Would be easier if i can check it directly. If possible, you can contact me at [email protected]

    Thanks,
    Bagus

    Plugin Author Bagus

    (@contactjavas)

    Hi @careerbuggy , @giriposhaneshwar , and @rozv
    In case you need faster response, here’s Discord invite link.

    With discord, i’m always notified.

    Plugin Author Bagus

    (@contactjavas)

    Hi @careerbuggy & @rozv ,
    In case you’re still facing this problem, here is the fix:

    1. Make sure the filter is added directly without hook
    2. If you’re adding the filter through theme (like in functions.php), and doing step above still doesn’t work, then you need move the filter from theme to a plugin. Maybe create a 1 file plugin which contains the filter?

    Please let me know if that works.
    Or maybe Join discord channel for faster response.

    Best,
    Bagus

    @contactjavas thank you for all your help! after trying different things, it worked as a separate plugin. thanks!

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘Whitelisting Endpoints function do not work’ is closed to new replies.