jwt-auth icon indicating copy to clipboard operation
jwt-auth copied to clipboard

Access Denied on everything except for /token & /token/validate

Open rexwreyes opened this issue 2 years ago • 4 comments

I can get the token and validate it with no issues. Trying to hit any other endpoint however I get Access Denied. I thought i saw some method of whitelisting the routes you want to use but can't seem to figure out how to do this.

rexwreyes avatar Feb 07 '23 16:02 rexwreyes

Hello @rexwreyes, I assume you've read the "Whitelisting Endpoints" section here? If it's not working for you, please do paste some code that you're using, and I'll be happy to check it over.

dominic-ks avatar Feb 07 '23 17:02 dominic-ks

I have this in my functions.php

add_filter( 'jwt_auth_whitelist', function ( $endpoints ) { $your_endpoints = array( '/wp-json/mesilinka/v1/upload', ); return array_unique( array_merge( $endpoints, $your_endpoints ) ); } );

Is this right? Should it be somewhere else?

rexwreyes avatar Feb 07 '23 17:02 rexwreyes

oh here is the rest init

add_action('rest_api_init', function () { register_rest_route('mesilinka/v1', '/upload', array( 'methods' => 'POST', 'callback' => 's3toPost', 'permission_callback' => function () { return true; }, 'args' => array( 'id' => array( 'validate_callback' => function ($param, $request, $key) { return is_numeric($param); } ), ), )); });

rexwreyes avatar Feb 07 '23 17:02 rexwreyes

OK, that looks like it should work, though I haven't tested it. To ask an obvious question, I assume you are sending the JWT with your requests once you've got one...? What error are you getting exactly?

dominic-ks avatar Feb 10 '23 16:02 dominic-ks