openhab-addons: [HTTP] Basic auth not working when configured in thing
Problem: Basic Auth seems to be not working when filling username/password in the UI thing configuration
Version: OpenHAB 3.0 Release
Created HTTP thing with one channel to query a REST API with a GET request: (please ignore the additonal headers, I added them later on to get it going as a workaround)
UID: http:url:openems-rest
label: OpenEMS
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
baseURL: http://examplehost:8084/rest/channel/
password: admin
refresh: 30
commandMethod: PUT
contentType: application/json
timeout: 3000
username: admin
bufferSize: 2048
headers:
- Authorization=Basic YWRtaW46YWRtaW4=
channels:
- id: meter0ActivePower
channelTypeUID: http:string
label: meter0ActivePower
description: ""
configuration:
mode: READONLY
stateExtension: meter0/ActivePower
This happens:
20:28:14.396 [TRACE] [http.internal.http.RefreshingUrlCache] - Sending to 'http://kube.gruning.eu:8084/rest/channel/meter0/ActivePower': Method = {GET}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813}, Content = {null}
20:28:14.397 [TRACE] [tp.internal.http.HttpResponseListener] - Received from 'http://kube.gruning.eu:8084/rest/channel/meter0/ActivePower': Code = {400}, Headers = {Date: Mon, 28 Dec 2020 19:28:14 GMT, Content-Type: application/json, Content-Length: 127, Server: Jetty(9.4.32.v20200930)}, Content = {{"jsonrpc":"2.0","id":"00000000-0000-0000-0000-000000000000","error":{"code":1003,"message":"Authentication failed","data":[]}}}
20:28:14.398 [WARN ] [tp.internal.http.HttpResponseListener] - Requesting 'http://kube.gruning.eu:8084/rest/channel/meter0/ActivePower' (method='GET', content='null') failed: 400 Bad Request
Then I manually added the authorization header which then leads to the expected result:
20:29:31.162 [TRACE] [http.internal.http.RefreshingUrlCache] - Sending to 'http://kube.gruning.eu:8084/rest/channel/meter0/ActivePower': Method = {GET}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Authorization: Basic YWRtaW46YWRtaW4=}, Content = {null}
20:29:31.166 [TRACE] [tp.internal.http.HttpResponseListener] - Received from 'http://kube.gruning.eu:8084/rest/channel/meter0/ActivePower': Code = {200}, Headers = {Date: Mon, 28 Dec 2020 19:29:31 GMT, Content-Type: application/json, Content-Length: 48, Server: Jetty(9.4.32.v20200930)}, Content = {{"value":1427,"type":"integer","writable":false}}
20:29:31.167 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'OpenEMS_meter0ActivePower' changed from NULL to {"value":1427,"type":"integer","writable":false}
To me it looks like there is no authorization header in the request at all (despite config in the UI). Looks like a bug to me?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (8 by maintainers)
Yes, I‘ll add a check for that.
Fixed. Forgot an URL part.
Hmm, strange. That works like a charm. Even if I change it to include a state URL extension. I have no clue. In my setup I can query the URL when using a browser extension (like RESTer for Firefox) or when manually adding the header with the HTTP binding. I will try to dive into this by looking at the server side debug logs tomorrow.