Platform information:
Hardware: RaspberryPi 4, 8GB
OS: Raspbian GNU/Linux 10 (buster)
Java Runtime Environment: Zulu11.50+19-CA (build 11.0.12+7-LTS)
openHAB version: 3.4.1 - Release Build
JavaScript: ECMAscript 2021
Problem: When trying to use basic authentication via sendHttpGetRequest to an external web server (i.e. external to openHab but on site, same LAN inside my firewall) I can not find any way of making it work. I have tried all possible combinations that I can imagine but the response from openHab is the same:
2023-03-22 22:22:34.928 [ERROR] [enhab.core.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.ExecutionException: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: Authentication challenge without WWW-Authenticate header
I have tried curl both via the Linux CLI and scripts and it returns data as expected. but not sendHttpGetRequest. I do realize that curl is not using Jetty the same was as openHab/Eclipse and I’m starting to suspect the problem is in the implementation.
This code snipplet (one of many attempts) is using the header:
var serverIP = "192.168.xx.xxx";
var serviceRequestPerArray = "/api/v1/production/inverters";
var serviceCreds = "user:password";
var headerHashMap = {
'Host' : '192.168.xx.xxx',
'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0',
'Accept' : 'application/json',
'Accept-Language' : 'sv-SE,sv;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding' : 'gzip, deflate',
'DNT' : '1',
'WWW-Authenticate' : 'Basic',
'Authorization' : 'Basic aW5zdski6HVyOmJqZTQ1NGM1', //This is username:password Base-64 encoded
};
// Get data for the total array
rawData = "";
totalURL = "http://" + serverIP + serviceRequestPerArray;
rawData = actions.HTTP.sendHttpGetRequest(totalURL,headerHashMap,5000);
console.info("rawData:" + rawData);
In another incarnation of the code, I use the “traditional” way:
var serverIP = "192.168.xx.xxx";
var serviceRequestPerArray = "/api/v1/production/inverters";
var serviceCreds = "user:password";
var headerHashMap = {
'Host' : '192.168.xx.xxx',
'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0',
'Accept' : 'application/json',
'Accept-Language' : 'sv-SE,sv;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding' : 'gzip, deflate',
'DNT' : '1',
};
// Get data for the total array
rawData = "";
totalURL = "http://user:password@" + serverIP + serviceRequestPerArray;
rawData = actions.HTTP.sendHttpGetRequest(totalURL,headerHashMap,5000);
console.info("rawData:" + rawData);
Both of these versions (and a number of iterations) result in the error above. I have seen basic authentication discussed in a number of threads here on the forum, mostly related to the iOS app but no help there. To play it safe (?) I also enabled Implicit User Role and allowed the Basic Authentication in MainUI → Settings → API Security.
Right now, I’m out of bright ideas and need some help.