XiaoFaye / WooCommerce.NET

A .NET Wrapper for WooCommerce/WordPress REST API
MIT License
391 stars 217 forks source link

Authentication fails on HTTP REST calls (OAuth 1.0a "one-legged" auth) when using 127.0.0.1 instead of localhost in the URL. #760

Open noamaster opened 11 months ago

noamaster commented 11 months ago

Version Information

Steps to replicate the issue

  1. Set up a local WordPress server running on localhost (in my case, I used http://localhost:8777)
  2. 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.
  3. 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}}'
XiaoFaye commented 7 months ago

What is your Url setting in the Wordpress server?