Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

woocommerce_rest_authentication_error #325

Open
Ecsodikas opened this issue Apr 12, 2022 · 1 comment
Open

woocommerce_rest_authentication_error #325

Ecsodikas opened this issue Apr 12, 2022 · 1 comment

Comments

@Ecsodikas
Copy link

Ecsodikas commented Apr 12, 2022

Hello everyone,

I'm currently trying to build a WordPress plugin that communicates with the WooCommerce API. This library looked like the perfect fit for the job but I can't get it to run on my local development machine.

The WordPress/WooCommerce setup is working fine because I can query the API without any problems from Postman. The problem starts when I want to use the library.

$this->wc_client = new Client(
            $url,
            $consumer_key,
            $consumer_secret,
            [
                'wp_api' => true,
                'query_string_auth' => true,
            ]
        );

This is how I create the client. And I am 100% sure the consumer_key and consumer_secret is correct, because they work via Postman.

My query looks like this:

$result = $this->wc_client->get('products');

The result I get is a HttpClientException with a woocommerce_rest_authentication_error and the message that the signature does not match.
Edit: The status code I receive is 401.

I'm pretty sure this is because I don't have a secure connection set up on my machine, but it feels like there should be an easier solution for a development environment.

Has someone solved this problem already?

Thanks in advance!

@Ecsodikas
Copy link
Author

I solved the issue.

It is important that the URL you pass into the Client matches the URL of the wordpress instance. Which should not normally not be a problem. But using docker and using a port mapping thats not mapping the same ports, i.e. 8080:80 instead of 80:80, changes things. Now the signature for OAuth get's calculated in the wrong way. I solved the issue by changing the internal port of my wordpress container to 8080 aswell, so my mapping finally became 8080:8080. Everything works fine now.

If you want to do the same thing and you are using the wordpress docker image, remember to change the virtual host in the /etc/apache2/sites-enabled/000-default.conf file AND in the /etc/apache2/ports.conf file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant