Support » Plugin: JWT Auth - WordPress JSON Web Token Authentication » Whitelisting Endpoints function do not work

  • 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 9 replies - 16 through 24 (of 24 total)
  • Plugin Author Bagus

    (@contactjavas)

    Hi all!
    FYI, wp-json/wp/v2/* is now whitelisted by default in v1.4.0

    I have my rest controller within my custom theme.
    To get filter ‘jwt_auth_whitelist’ work, I needed to put the code in functions.php right to the top (first lines of the file).

    • This reply was modified 3 months, 1 week ago by afatoga.

    Hi Mr. @contactjavas ,
    I still have the same problem not solved,
    I tried to put the following code:
    add_filter(
    ‘jwt_auth_whitelist’,
    function ($endpoints) {
    return array(
    ‘/wp-json/oembed/1.0/*’,
    ‘/wp-json/wp/v2/*’,
    ‘/wp-json/post-views-counter/*’,
    ‘/wp-json/yoast/v1/*’,
    ‘/wp-json/yoast/v1/myyoast/*’,
    ‘/wp-json/wc/blocks/*’,
    ‘/wp-json/wc/store/*’,
    ‘/wp-json/wc/v1/*’,
    ‘/wp-json/wc/v2/*’,
    ‘/wp-json/wc/v3/*’,
    ‘/wp-json/wccom-site/v1/*’,
    ‘/wp-json/wc-analytics/*’,
    ‘/wp-json/wc-admin/*’,
    );
    }
    );
    as you said once in my function.php and then in my plugin __constructor before rest_api_init action and in add_action(‘plugins_loaded’) and all of them didn’t work.
    Please help me if you could.
    Thanks!

    • This reply was modified 2 months, 1 week ago by nawarcr7.
    Plugin Author Bagus

    (@contactjavas)

    Hi @nawarcr7 , try to delete your existing whitelisting filter. Put it in functions.php outside of your class. Just put it without wrapping it into a class.

    
    add_filter(
    	'jwt_auth_whitelist',
    	function ( $endpoints ) {
    		$whitelists = array(
    			'/wp-json/oembed/1.0/*',
    			'/wp-json/wp/v2/*',
    			'/wp-json/post-views-counter/*',
    			'/wp-json/yoast/v1/*',
    			'/wp-json/yoast/v1/myyoast/*',
    			'/wp-json/wc/blocks/*',
    			'/wp-json/wc/store/*',
    			'/wp-json/wc/v1/*',
    			'/wp-json/wc/v2/*',
    			'/wp-json/wc/v3/*',
    			'/wp-json/wccom-site/v1/*',
    			'/wp-json/wc-analytics/*',
    			'/wp-json/wc-admin/*',
    		);
    
    		foreach ( $whitelists as $whitelist ) {
    			if ( ! in_array( $whitelist, $endpoints, true ) ) {
    				array_push( $endpoints, $whitelist );
    			}
    		}
    
    		return $endpoints;
    	}
    );
    

    Thank you @contactjavas for your quick response,
    I’m sorry, but still not working! as below:

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

    Just for being noticed, if I use var_dump() with this $whitelists array in my filter, it is rendered successfully but it didn’t affect any of my routes.

    • This reply was modified 2 months, 1 week ago by nawarcr7.
    • This reply was modified 2 months, 1 week ago by nawarcr7.
    Plugin Author Bagus

    (@contactjavas)

    Hi @nawarcr7 , can you give screenshot of your postman testing? You can join our Discord channel for easier troubleshooting.

    Thanks,
    Bagus

    Hi @contactjavas, I have joined Discord.

    Hello A, I have the same problem, I have read the documentation of your plugin, and when I do it is the same as above.

    code:
    add_filter( ‘jwt_auth_whitelist’, function ( $endpoints ) {
    return array(
    ‘/wp-json/bdpwr/v1/reset-password’,
    ‘/wp-json/bdpwr/v1/set-password’,
    ‘/wp-json/bdpwr/v1/validate-code’,
    );
    } );

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

    hi there, im in the same issue, it’s not working in my function.php
    but i dont understand this phrase: “Maybe create a 1 file plugin which contains the filter”.
    where this filter take place? Where would i need put this function add_filter( 'jwt_auth_whitelist', function ( $endpoints )
    Inside any .php file in my plugin folder?!

    i’m really basic changing code in WP sorry.
    best!
    juanma

Viewing 9 replies - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.