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

JWT auth #399

Open
igitur opened this issue Aug 13, 2019 · 5 comments

Comments

@igitur
Copy link

commented Aug 13, 2019

Versions

  • Wordpress version 5.2.2
  • WooCommerce version 3.7.0
  • WooCommerce.NET version: latest commit from GitHub f892c81

Replication

RestAPI rest = new RestAPI("http://www.mydomain.com/wp/wp-json/jwt-auth/v1/token", "", "");
WCObject wc = new WCObject(rest);

Details of the error message if there is any

Exception is thrown:

System.Exception: Please use WooCommerce Restful API Version 2 url for this WCObject. e.g.: http://www.yourstore.co.nz/wp-json/wc/v2/
   at WooCommerceNET.WooCommerce.v2.WCObject`15..ctor(RestAPI api) in C:\dev\WooCommerce.NET\WooCommerce\v2\WCObject.cs:line 23
   at WooCommerceNET.WooCommerce.v2.WCObject..ctor(RestAPI api) in C:\dev\WooCommerce.NET\WooCommerce\v2\WCObject.cs:line 178
   at ConsoleApp1.Program.Main(String[] args) in C:\temp\ConsoleApp1\Program.cs:line 29

Exception is thrown at https://github.com/XiaoFaye/WooCommerce.NET/blob/master/WooCommerce/v2/WCObject.cs#L21 because api.Version == APIVersion.WordPressAPIJWT, not APIVersion.Version2.

I see recent changes have been made to https://github.com/XiaoFaye/WooCommerce.NET/blob/master/RestAPI.cs#L81 to set the url and .Version for JWT

@XiaoFaye

This comment has been minimized.

Copy link
Owner

commented Aug 13, 2019

It should be WPObject wp = new WPObject(rest);

WCObject is for WooCommerce, WPObject is for WordPress

@igitur

This comment has been minimized.

Copy link
Author

commented Aug 14, 2019

Ah, thanks, I misunderstood.

So how can I access WooCommerce objects, e.g. Products, using JWT auth?

@igitur

This comment has been minimized.

Copy link
Author

commented Aug 14, 2019

Sorry to say this, but the documentation is really poor. I can't figure out what the prerequisites to do just a normal set up. For example, I also realised that https is required for basic auth. This is a WooCommerce requirement, but I would have expected this to be explicitly listed in this repo's README.

Are the JWT or OAuth plugins a prerequisite or are they an optional alternative way of authenticating?

And many more questions....

Dude, I promise I will buy you a coffee☕️ if you set up clear, understandable documentation with a full working client project. Even your code samples on the README page can't compile (you're declare the p variable twice).

@XiaoFaye

This comment has been minimized.

Copy link
Owner

commented Aug 14, 2019

Hi, sorry if the document got you confused.

  • WooCommerce ONLY supports OAuth for now, no plugins needed.
  • WooCommerce.NET will use basic auth for WooCommerce API if you pass https URL, this is done automatically.
  • JWT and OAuth plugins is for WordPress API authentication ONLY.
  • The code samples is for usage demonstration ONLY, it's NOT a demo project.

Thanks for your suggestions, I will try to improve the documents and make it more user-friendly.

@igitur

This comment has been minimized.

Copy link
Author

commented Aug 15, 2019

Thanks. I eventually succeeded with https + basic auth. Once I get everything working, I'll make a pull request to improve the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.