Hi again @2f4u
So, I did some testing this evening and I unfortunately cannot replicate your issue. I hope that if I explain the steps I went through, perhaps you can indicate somewhere I went off base. Apologies in advance for the wall of text.
I first went to the wp.org repository and downloaded the first plugin you had mentioned when starting this conversation https://www.ads-software.com/plugins/jwt-authentication-for-wp-rest-api/ I’m running everything on my own machine using Local by WPEngine
Per their documentation, I first added this to my .htaccess
file
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
Then I added these to my wp-config.php
file
define('JWT_AUTH_SECRET_KEY', '12345');
define('JWT_AUTH_CORS_ENABLE', true);
I created a quick REST endpoint which simply replies with “Hello World”, which on my test site lives at /wp-json/binarytemplar/v1/test
. I then went into the Disable REST API
settings and ensured that Unauthenticated users do NOT have permission to this endpoint but Contributors do. Testing in a browser, I was able to confirm that these settings were working as expected for both user roles.
I then fired up Postman to test some remote posts to the JWT endpoints. First I created one which does a POST to the /wp-json/jwt-auth/v1/token
route with my contributor’s username/password. This is my response
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZGlzYWJsZS1yZXN0LWFwaS5sb2NhbCIsImlhdCI6MTYzNDYwNjEwMCwibmJmIjoxNjM0NjA2MTAwLCJleHAiOjE2MzUyMTA5MDAsImRhdGEiOnsidXNlciI6eyJpZCI6IjIifX19.0_Kmhh0YmS6pwqFSvxdjyi9WTZyeRpxk3O6lKDZinsQ",
"user_email": "[email protected]",
"user_nicename": "cont",
"user_display_name": "cont"
}
Using that token, I created a second test in Postman which does a GET to /wp-json/binarytemplar/v1/test
but passes the extra header as specified. With this token passed in the headers, I get a correct response and see Hello World
reply from the route.
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZGlzYWJsZS1yZXN0LWFwaS5sb2NhbCIsImlhdCI6MTYzNDYwNjEwMCwibmJmIjoxNjM0NjA2MTAwLCJleHAiOjE2MzUyMTA5MDAsImRhdGEiOnsidXNlciI6eyJpZCI6IjIifX19.0_Kmhh0YmS6pwqFSvxdjyi9WTZyeRpxk3O6lKDZinsQ
If I do NOT pass this token (eg: attempt to access as an Unauthenticated user) I get the DRA blocking error which is expected
{
"code": "rest_cannot_access",
"message": "DRA: Only authenticated users can access the REST API.",
"data": {
"status": 401
}
}
Can you confirm if any of this doesn’t line up with what you are doing on your end? Are you able to see any more details about the 401 you are getting in response?
Cheers!