I am using the rest api in WordPress. For authentication I use the Basic authentication plugin (JSON Basic Authentication)

I use this request (from both postman and nodejs):

POST /wp-json/wp/v2/posts HTTP/1.1
Host: **************
Authorization: Basic *********************
Content-Type: application/json
Cache-Control: no-cache

{ "title": "test", "content": "test", "status": "private", "excerpt": "test" }

When testing locally on my server, it works fine but on a VPS I get the following error:

{
    "code": "rest_cannot_create",
    "message": "Sorry, you are not allowed to create posts as this user",
    "data": {
        "status": 401
    }
}

I know the user credentials are correct and the user is allowed to create posts.

I suspect that the auth header is lost somewhere before arriving to rest-api. But where should I start debugging? Which logs?

2 Answers
2

Authorization header is usually stripped by Apache.

You can fix it with .htaccess

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

Leave a Reply

Your email address will not be published. Required fields are marked *