usefulteam / jwt-auth

WordPress JSON Web Token Authentication
https://wordpress.org/plugins/jwt-auth/
122 stars 49 forks source link

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

Open rexwreyes opened 1 year ago

rexwreyes commented 1 year ago

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.

dominic-ks commented 1 year ago

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.

rexwreyes commented 1 year ago

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 commented 1 year ago

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); } ), ), )); });

dominic-ks commented 1 year ago

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?