diff --git a/RestAPI.cs b/RestAPI.cs
index 9eea075..4ebc438 100644
--- a/RestAPI.cs
+++ b/RestAPI.cs
@@ -3,8 +3,6 @@
using System.IO;
using System.Linq;
using System.Net;
-using System.Net.Http;
-using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
@@ -43,7 +41,7 @@ public class RestAPI
///
/// Authenticate Woocommerce API with JWT when set to True
///
- public bool WCAuthWithJWT { get; set; }
+ internal bool WCAuthWithJWT { get; set; }
///
/// Provide a function to modify the json string before deserilizing, this is for JWT Token ONLY!
@@ -79,11 +77,13 @@ public RestAPI(string url, string key, string secret, bool authorizedHeader = tr
Func jsonSerializeFilter = null,
Func jsonDeserializeFilter = null,
Action requestFilter = null,
- Action responseFilter = null)//, bool useProxy = false)
+ Action responseFilter = null,
+ bool wcAuthWithJWT = false)//, bool useProxy = false)
{
if (string.IsNullOrEmpty(url))
throw new Exception("Please use a valid WooCommerce Restful API url.");
+ WCAuthWithJWT = wcAuthWithJWT;
string urlLower = url.Trim().ToLower().TrimEnd('/');
if (urlLower.EndsWith("wc-api/v1") || urlLower.EndsWith("wc-api/v2") || urlLower.EndsWith("wc-api/v3"))
Version = APIVersion.Legacy;
@@ -113,7 +113,7 @@ public RestAPI(string url, string key, string secret, bool authorizedHeader = tr
AuthorizedHeader = authorizedHeader;
//Why extra '&'? look here: https://wordpress.org/support/topic/woocommerce-rest-api-v3-problem-woocommerce_api_authentication_error/
- if ((url.ToLower().Contains("wc-api/v3") || !IsLegacy) && !wc_url.StartsWith("https", StringComparison.OrdinalIgnoreCase) && !(Version == APIVersion.WordPressAPI || Version == APIVersion.WordPressAPIJWT))
+ if ((url.ToLower().Contains("wc-api/v3") || !IsLegacy) && !wc_url.StartsWith("https", StringComparison.OrdinalIgnoreCase) && !(Version == APIVersion.WordPressAPI || Version == APIVersion.WordPressAPIJWT) && (!WCAuthWithJWT))
wc_secret = secret + "&";
else
wc_secret = secret;
@@ -213,7 +213,7 @@ public virtual async Task SendHttpClientRequest(string endpoint, Requ
else
{
httpWebRequest = (HttpWebRequest)WebRequest.Create(wc_url + GetOAuthEndPoint(method.ToString(), endpoint, parms));
- if (Version == APIVersion.WordPressAPIJWT)
+ if (JWT_Object != null)
httpWebRequest.Headers["Authorization"] = "Bearer " + JWT_Object.token;
}
@@ -336,7 +336,7 @@ protected string GetOAuthEndPoint(string method, string endpoint, Dictionary dic = new Dictionary();
dic.Add("oauth_consumer_key", wc_key);
@@ -364,7 +364,7 @@ protected string GetOAuthEndPoint(string method, string endpoint, Dictionary