Support » Plugin: JWT Auth - WordPress JSON Web Token Authentication » Whitelisting is not working

  • I’ tired of try to add my endpoints to the the white list.
    I read the documentation and similar problems in the forum but it continue, my code:

    1- I’m using one plugin (Code Snippets) to add the filter, this is my code:

    add_action( ‘plugins_loaded’, ‘my_plugin_override’ );

    function my_plugin_override() {
    // add white list endpoints
    add_filter( ‘jwt_auth_whitelist’, function ( $endpoints ) {
    return array(
    ‘/wp-json/acf/v3/users’,
    ‘/wp-json/acf/v3/’,
    );
    }
    );

    }

    2- This is my response in Postman
    {
    “success”: false,
    “statusCode”: 403,
    “code”: “jwt_auth_no_auth_header”,
    “message”: “Header för autentisering hittades inte.”,
    “data”: []
    }

    Thanks for help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter alvar05

    (@alvar05)

    I also add the code to funtions.php of the theme.

    Plugin Author Bagus

    (@contactjavas)

    Hi @alvar05 , are those ACF’s endpoints?

    Instead of those 2 endpoints, you can just whitelist this: /wp-json/acf/v3/* (note the * symbol).

    Well, the documentation is quite misleading (it needs refinements :D). Try this:

    
    <?php
    add_action( 'plugins_loaded', 'my_plugin_override' );
    
    function my_plugin_override() {
    	// Add white list endpoints.
    	add_filter(
    		'jwt_auth_whitelist',
    		function ( $endpoints ) {
    			$whitelists = array(
    				'/wp-json/acf/v3/*',
    			);
    
    			foreach ( $whitelists as $whitelist ) {
    				if ( ! in_array( $whitelist, $endpoints, true ) ) {
    					array_push( $endpoints, $whitelist );
    				}
    			}
    
    			return $endpoints;
    		}
    	);
    }
    
    
    Plugin Author Bagus

    (@contactjavas)

    And you don’t need to put it twice. Just put it either in a plugin or in functions.php (not both).

    Cheers 🙂
    Bagus

    Hi @contactjavas. i also have same issue. tried everything but whitelist cannot work even with shortest code. i put in everything. theme plugin functions.php, custom plugin. but the response is always 403. i really need your help.

    this is my code

    add_action( ‘plugins_loaded’, ‘my_plugin_override’ );

    function my_plugin_override() {
    // Add white list endpoints.
    add_filter(
    ‘jwt_auth_whitelist’,
    function ( $endpoints ) {
    $whitelists = array(
    ‘/wp-json/benny_flutter/*’,
    );

    foreach ( $whitelists as $whitelist ) {
    if ( ! in_array( $whitelist, $endpoints, true ) ) {
    array_push( $endpoints, $whitelist );
    }
    }

    return $endpoints;
    }
    );
    }

    Plugin Author Bagus

    (@contactjavas)

    Hi @bennydeveloper01 , what’s url full url endpoint? (it’s ok if it’s still in local)

    I’m also having the same issue. None of the above methods work for me.

    • This reply was modified 10 months, 2 weeks ago by lexdubyna.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Whitelisting is not working’ is closed to new replies.