SenseTecnic / node-red-contrib-osisoft-web-api

A node module for connecting to OSIsoft Web API Server
Apache License 2.0
3 stars 8 forks source link

inject msg.headers{"X-Requested-With"} for web-api-write #5

Closed jtkhair closed 1 year ago

jtkhair commented 1 year ago

Machine configuration Node-red version: v3.0.2 OS: Windows 11 httpNodeCors: enabled

PI webapi configuration Authentication method: "Basic" EnableCSRFDefense flag: "True"

Issue: web-api-write produce 403 error. HTTP POST calls works using POSTMAN and Node-red HTTP request by defining "X-Requested-With" in the headers even with httpNodeCors disabled.

I created a function to set the payload and headers node before the pi-web-api-write node for both webid and point path but still getting the same 403 error.

Please advise.

jtkhair commented 1 year ago

solved with editing the osisoft-web-api.js

webAPIClientNode.prototype.writeByCustomUrl = function (protocol, url, method, data, node) { return new Promise(function(resolve, reject) { var requestOptions = { url: protocol + node.server.baseUrl + url, headers: { 'Authorization': node.server.generateAuth(), 'Content-Type': 'application/json', 'X-Requested-With' : '*' //Proposed add-in to Allow Write data connection via pi web api to PI when "EnableCSRFDefense": true },