WooCommerce.NET
WooCommerce.NET copied to clipboard
Authentication fails on HTTP REST calls (OAuth 1.0a "one-legged" auth) when using 127.0.0.1 instead of localhost in the URL.
Version Information
- WordPress Version: 5.9.3
- WooCommerce Version: 6.5.1
- WooCommerce.NET Version: 0.8.6
Steps to replicate the issue
- Set up a local WordPress server running on localhost (in my case, I used http://localhost:8777)
- Using WooCommerce.NET, construct a new RestAPI class with url set to
http://127.0.0.1:8777/wp-json/wc/v3/and pass in a correct key and secret. - Create a WCObject and call wc.Customer.GetAll() to get the error.
Note if you replace http://127.0.0.1:8777/wp-json/wc/v3/ with http://localhost:8777/wp-json/wc/v3/, authentication works correctly. My guess is that the OAuth signature on the server is always calced using localhost while WooCommerce.NET uses 127.0.0.1 when generating the signature before making the request.
Details of the error message if there is any
The error message from the server call is as follows:
System.Net.WebException: '{"code":"woocommerce_rest_authentication_error","message":"Invalid signature - provided signature does not match.","data":{"status":401}}'
What is your Url setting in the Wordpress server?