Hello,
I would like to ask you for help setting up thing new HTTP binding to talk to OH3 API.
What I would like to do (it was working on OH2 with old http binding) is access API to get z-wave device status.
For example API url for device is:
http://192.168.0.131:8080/rest/things/zwave:device:711ae217:node40
When i go to that url there is “Authentication required” 401 error which is correct.
Using curl from cmd:
curl -X GET -u user:password --header "Accept: application/json" "http://192.168.0.131:8080/rest/things/zwave:device:711ae217:node40"
I am getting right response with all data.
When I try to setup file with thing:
Thing http:url:zwavehttp "Z-Wave HTTP" [
baseURL="http://192.168.0.131:8080/rest/things",
username="user",
password="password",
headers="Accept=application/json",
refresh=600] {
Channels:
Type string : ZWAVE_DEVICE1 "Z-Wave Device 1 Status" [ stateExtension="zwave:device:711ae217:node40", stateTransformation="JSONPATH:$.statusInfo.status" ]
}
I am getting error:
[p.internal.http.HttpResponseListener] - Requesting 'http://192.168.0.131:8080/rest/things/zwave:device:711ae217:node40' (method='GET', content='null') failed: HTTP protocol violation: Authentication challenge without WWW-Authenticate header
Maybe @J-N-K can help me
Probably I am making mistake somewhere but I don’t know where even after reading the documentation https://www.openhab.org/addons/bindings/http/
I would perhaps try removing your Things file for now and setting this up first with the UI. Once that’s working then we can migrate back to the Things file.
JNK is no longer an openHAB maintainer, nor supports configurations in Things files.
WIth GUI I have created code like below:
UID: http:url:0c27989d94
label: zwavehttp
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
headers:
- Accept=application/json
baseURL: http://192.168.0.131:8080/rest/things
password: password
refresh: 60
commandMethod: GET
timeout: 10000
username: username
bufferSize: 2048
channels:
- id: test
channelTypeUID: http:string
label: test
description: ""
configuration:
mode: READWRITE
stateExtension: /zwave:device:711ae217:node40
stateTransformation: JSONPATH:$.statusInfo.status
but it produces the same error:
[p.internal.http.HttpResponseListener] - Requesting 'http://192.168.0.131:8080/rest/things/zwave:device:711ae217:node40' (method='GET', content='null') failed: HTTP protocol violation: Authentication challenge without WWW-Authenticate header
J-N-K
(Jan N. Klug)
March 9, 2021, 1:08pm
4
Did you try BASIC_PREEMPTIVE
as auth method?
In GUI there is no BASIC_PREEMPTIVE
directly
so I have put it in the code:
UID: http:url:0c27989d94
label: zwavehttp
thingTypeUID: http:url
configuration:
authMode: BASIC_PREEMPTIVE
ignoreSSLErrors: false
headers:
But with no luck.
2021-03-09 15:39:24.506 [WARN ] [re.config.core.internal.ConfigMapper] - Could not set field value for field 'authMode': No enum constant org.openhab.binding.http.internal.config.HttpAuthMode.BASIC_PREEMPTIVE
java.lang.IllegalArgumentException: No enum constant org.openhab.binding.http.internal.config.HttpAuthMode.BASIC_PREEMPTIVE
J-N-K
(Jan N. Klug)
March 9, 2021, 2:44pm
6
Which version are you using?
I have version 3.0.1 delivered by default with OH3 3.01 release.
I can confirm this also:
runtimeInfo:
version: 3.0.1
buildString: Release Build
locale: en_GB
systemInfo:
configFolder: /etc/openhab
userdataFolder: /var/lib/openhab
logFolder: /var/log/openhab
javaVersion: 11.0.10
javaVendor: Azul Systems, Inc.
javaVendorVersion: Zulu11.45+27-CA
osName: Linux
osVersion: 4.15.0-136-generic
osArchitecture: i386
availableProcessors: 2
freeMemory: 25678600
totalMemory: 163577856
bindings:
- astro
- http
- mqtt
- network
- telegram
...
userAgent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0
J-N-K
(Jan N. Klug)
March 9, 2021, 8:22pm
9
It could be that this was introduced later and is only available in latest milestone.
Maybe I can try tomorrow, not sure if I find the time to do so.
J-N-K
(Jan N. Klug)
March 13, 2021, 8:53am
10
You have two issues.
Token Auth is currently not supported by the binding.
I have Basic Authentication enabled:
So as far as I understand my only way is to wait for next binding release?
J-N-K
(Jan N. Klug)
March 13, 2021, 10:50am
12
Correct. The REST API expects the Auth header to be sent without requesting that.
Usually the flow would be
Client: „request something“
Server: „you need to auth, here is the challenge“
Client: „here are my credentials and the request again“
Step 2 is missing, so the Client (the binding) will never send the corresponding header. This can be forced by always sending the header (which is what preemptive does).
I have upgraded my openHAB to 3.1.0.M2 - Milestone Build and tested latest HTTP binding and it waorks as suggested (with BASIC_PREEMPTIVE authMode)
I will paste my config - maybe it will be useful for someone.
Thing configuration:
Thing http:url:zwavehttp "Z-Wave Status HTTP" [
baseURL="http://192.168.0.100:8080/rest/things",
username="user",
password="pass",
authMode="BASIC_PREEMPTIVE",
stateMethod="GET",
commandMethod="GET",
refresh=3600,
timeout=10000
]
{
Channels:
Type string : Item_1_ZWave_status "Item 1 Z-Wave Status" [ stateExtension="zwave:device:711ae317:node1", stateTransformation="JSONPATH:$.statusInfo.status" ]
Type string : Item_1_Last_Wakeup "Item 1 Last Wakeup" [ stateExtension="zwave:device:711ae317:node1", stateTransformation="JSONPATH:$.properties.zwave_lastwakeup" ]
Type string : Item_2_ZWave_status "Item 2 Z-Wave Status" [ stateExtension="zwave:device:711ae317:node2", stateTransformation="JSONPATH:$.statusInfo.status" ]
Type string : Item_2_Last_Wakeup "Item 2 Last Wakeup" [ stateExtension="zwave:device:711ae317:node2", stateTransformation="JSONPATH:$.properties.zwave_lastwakeup" ]
}
Items configuration:
String item_1_zwave_status "Z-Wave Status [%s]" {channel="http:url:zwavehttp:Item_1_ZWave_status"}
DateTime item_1_LastWakeup "[%1$tY-%1$tm-%1$td %1$tH:%1$tM]" {channel="http:url:zwavehttp:Item_1_Last_Wakeup"}
String item_2_zwave_status "Z-Wave Status [%s]" {channel="http:url:zwavehttp:Item_2_ZWave_status"}
DateTime item_2_LastWakeup "[%1$tY-%1$tm-%1$td %1$tH:%1$tM]" {channel="http:url:zwavehttp:Item_2_Last_Wakeup"}