1
votes

I have wordpress 5.4.1 and woocommerce 4.2 and ssl certificate from let's encrypt

I managed to get a response from the API before using query string https://www.store.com/wp-json/wc/v3/products?consumer_key=ck_XXXX&consumer_secret=cs_XXX but suddenly it stopped working giving me 401 unauthorized error. I am 100% sure about the keys.

I am using php with FastCgi and I read that sometimes the server dosn't read the authorization correctly so I tried the following

I added

<IfModule mod_setenvif>
  SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</IfModule>

and

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

to my .htaccess file

Also I added

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

to my httpd.conf file after RewriteEngine on

I also installed the basic auth plugin https://github.com/WP-API/Basic-Auth

All of the above solutions failed to get a response from postman or insomnia with the same error 401 unauthorized.

1

1 Answers

0
votes

I finally got the answer after 2 days

The best solution is to remove all the above and just add

RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]

so my whole htaccess block will look like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>