Fix WooCommerce auth: use query params instead of Basic auth header (proven working via curl)

This commit is contained in:
2026-10-15 22:48:09 +02:00
parent 659f7d603d
commit a329a03703
+10 -1
View File
@@ -9,16 +9,25 @@ module.exports = function (RED) {
const node = this;
node.baseUrl = (config.baseUrl || "https://example.com/wp-json/wc/v3").replace(/\/+$/, "");
// Credentials from node-RED credentials tab OR from config node fields
node.consumerKey = (this.credentials && this.credentials.consumerKey) || config.consumerKey || "";
node.consumerSecret = (this.credentials && this.credentials.consumerSecret) || config.consumerSecret || "";
node.sendRequest = function (method, path, body, msgHeaders, callback) {
const url = new URL(node.baseUrl + path);
// Append consumer_key and consumer_secret as query parameters (proven working in curl)
if (node.consumerKey) {
url.searchParams.set('consumer_key', node.consumerKey);
}
if (node.consumerSecret) {
url.searchParams.set('consumer_secret', node.consumerSecret);
}
const parsedBody = body !== undefined ? (typeof body === "string" ? body : JSON.stringify(body)) : undefined;
const headers = Object.assign({ "Accept": "application/json", "Content-Type": "application/json" }, msgHeaders || {});
if (parsedBody !== undefined) headers["Content-Length"] = Buffer.byteLength(parsedBody);
headers["Authorization"] = "Basic " + Buffer.from(node.consumerKey + ":" + node.consumerSecret).toString("base64");
const options = {
method, hostname: url.hostname,