woocommerce / wc-api-python

A Python wrapper for the WooCommerce API.
https://pypi.org/project/WooCommerce/
MIT License
212 stars 112 forks source link

Issue with authentication consumer key or consumer secret invalid #11

Closed assislucas closed 8 years ago

assislucas commented 8 years ago

I'm creating credentials using the endpoint /wc-auth/v1/authorize with _scope=readwrite most times the consumer key and secret that I get are valid, but a couple of times I get consumer key or consumer secrets that are invalid when I try to use them later in code like this:

wcapi = API(
    url=  shop_url,
    consumer_key= key,
    consumer_secret= secret
)
response = wcapi.get("orders?page=1")
# Then response.text is {"errors":[{"code":"woocommerce_api_authentication_error","message":"Consumer Secret is invalid"}]}
#  or {"errors":[{"code":"woocommerce_api_authentication_error","message":"Consumer Key is invalid"}]}

Has this issue been detected yet? Is it related to the python wrapper or woocommerce plugin?

claudiosanches commented 8 years ago

Under HTTPS or not?

assislucas commented 8 years ago

No, HTTP. Does it make a difference?

claudiosanches commented 8 years ago

Yes, of course, since can be an error in the nonce, here:

https://github.com/woothemes/wc-api-python/blob/master/woocommerce/oauth.py#L53-L57

assislucas commented 8 years ago

Ok yeah, actually I just checked. This problem is happening both over HTTP and HTTPS.

claudiosanches commented 8 years ago

If it happens in both, then it must be a problem with your server. Good, it was to try to change the way we created the nonces. Not a problem this wrapper.

claudiosanches commented 8 years ago

Anyway, you can test my new commit, it's a little better the way that nonces are created.

assislucas commented 8 years ago

I'm still experiencing the issue. In order to make sure that it's not a problem on the authorization endpoint which generates the tokens I've generated the tokens manually on woocommerce plugin settings. With the credentials I generated I'm doing exactly:

wcapi = API(
    url="https://storeurl.com/",
    consumer_key="ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    consumer_secret="cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
r = wcapi.get("orders?page=1")
r.json()
# This returns: {u'errors': [{u'message': u'Consumer Secret is invalid', u'code': u'woocommerce_api_authentication_error'}]}

How can the secret be invalid if I just generated and copied these values? And I'm using the master code on this project therefore it includes the commit 00bc2fe259578982f7cd27dae6201c69eae4bcc3

claudiosanches commented 8 years ago

This change is for oAuth... You said that you have this error without SSL. If you have just under SSL can be this:

http://woothemes.github.io/woocommerce-rest-api-docs/#authentication

Occasionally some servers may not parse the Authorization header correctly (if you see a “Consumer key is missing” error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters.

If you are not able to answer my questions, I will be unable to help you as well.

itasouza commented 7 years ago

Using Ionic 3 Now I have a new server, everything works in web-api, but now changed my error.

this.WooCommerce = WC({ url: "http://wooionic.esy.es", version: 'v3', // WooCommerce API version (optional) verifySsl: true, // Use false when need test with self-signed certificates, default is true (optional) encoding: 'utf8', // Encode, default is 'utf8' (optional) consumerKey: "ck_c5b919fa658a9d22a2a013326c18555a8b3c6c26", consumerSecret: "cs_b4b307338741da37cb7c4f96e299dfbb908f8d53" });

Error: The oauth_consumer_key parameter is missing.

Thanks for the help.

angelleye commented 7 years ago

@claudiosanches, I'm actually running into this now. For some reason when I use http:// in the store_url it's working fine, but when I use https:// it's telling me the secret is invalid.

You mentioned this means there's a problem at the server. Can you elaborate on that? I'm not sure what to tell my server guy..??