-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[remoteopenhab] Add in Username and Password to Connect Through OpenhabCloud #10055
Comments
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/remote-openhab-binding-access-rest-via-openhabcloud/116239/8 |
Your solution is apparently not working, I got a code 401 (Unauthorized):
This would require to analyze how openHAB Android app is handling the connection through myopenhab. |
It works on remote OH2.5.10 instance though. |
My server connected to myopenhab is OH3. |
I believe it has to do with some new changes on OpenHabCloud for OH3 such as X-OPENHAB-AUTH-HEADER=true, redirection which RemoteOpenhab Binding does not take into consideration. That is just my 2 cent which requires more investigation |
@lolodomo i checked on the traffic flow, I I believe it is httpclient that does not react to 302 response from remote openhab instance. I have also verified "setFollowRedirection=true" |
Are you meaning myopenhab.org redirected to home.myopenhab.org? So finally it was not working for you too? |
I just checked and the used HTTP client follows redirections (until 8 levels). And even the request is tagged to follow redirects. |
Here are what I find in the response headers:
|
I got success for HTTP requests with this kind of code:
Remains SSE requests... |
Yes it isn't working on OH3 because your code use /rest to check OH3 availability and etc. But the actual path is "/rest/?" Hence OH3 replies with 302 and Location pointing to /rest/?. Somehow httpckient ignore that response and timeout. Nevertheless the concept of adding in Username and password is correct and it is working as I can see the /rest request is punching through private openhanhab cloud |
I run /rest path to retrieve the different rest URL provided by the server. Then the used Rest URLs are the one provided by the server. I can try with /rest/? And I will try to disable redirection and see if I get a 302 error. |
Thank you very much for your help to analyze the problem. The code is now working if I setup "/rest/?" as restPath setting. I have everything in hands to finalize the change. I have to check if "/rest/?" could become the default REST path (in replacement to "/rest"). |
Cool |
Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
I discovered that even with a direct server access (from the local network), if I use "/rest" as endpoint, my request is redirected to "/rest/". Regarding the access through openHAB Cloud using the invalid endpoint ("/rest"), there are in fact two redirects:
I am now just telling me that I should disable the authorization header in requests in case HTTP protocol. is used and I should use it only in case HTTPS is used. This was not a real problem when using the binding in the local network but now that we could connect through the Net, I should take care to not provide these headers for unsecured requests. I will probably add a new setting to let users doing it but after enabling this setting. |
Fix the default rest path to avoid unnecessary redirects Add new configuration settings username, password and authenticateAnyway Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lsafelix75 : I have still one remaining problem, It concerns the REST API which are secured. I use one of them to retrieve the list and state of things on the remote server. For this one, I provided the double authorization headers, one Basic and one Bearer. Unfortunately, myopenhab is returniong a 400 bad request ! So at the moment, I have something working but without all features. |
Add new configuration settings username, password and authenticateAnyway Fix the default REST path to avoid unnecessary request redirects Provide the access token to requests only when necessary Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Add new configuration settings username, password and authenticateAnyway Fix the default REST path to avoid unnecessary request redirects Provide the access token to requests only when necessary Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
interesting, if I open MainUI from myopenhab in my WEB browser and then get the admin privilege, then the browser is just displaying a blank page ! Using MainUI in admin mode through myopenhab is apparently not possible. Issue opened to try to understand what is wrong: openhab/openhab-webui#907 |
Another issue tht I have noticed is your code uses the returned URLs for items, site maps directly instead of appending the domain name with the cloud url. I'm not sure whether this should be catered by remoteopenhab binding or openhabcloud. You will notice it if you use different port than standard one as the replied links' url do not have port included. |
Yes I see there is no port in the returned URLs but I thought it was only becayse the default port (443) is used.
The port is suppressed by Jetty when building the request ! Maybe that is the reason why the returned URLs in the response have no port. |
I observed the same with your. Port is just truncated. I guess there are only 2 options, either you change it in your code or have to trace who alter this, either openhabcloud or remote openhab connector. |
In the case of myopenhab, the port is truncated because useless (it is the default HTTPS port - 443). So I see no problem here. In case the returned URLs are without port while port is not 443, this is a bug but not a remote openHAB binding bug. An issue has to be opened for that. I assume this bug only affects users not using myooenhab but a dedicated openHAB Cloud instance with not standards ports. Hopefully it probably concerns only few expert users all around the world ;) |
And URLs returned by my server include port 8080 or 8443 so this is clearly not a OH server bug but probably an openHAB cloud bug. Issue to be opened here https://github.com/openhab/openhab-cloud |
I finally found the solution to my last problem: I must use header X-OPENHAB-TOKEN rather than Authorization. |
Add new configuration settings username, password and authenticateAnyway Fix the default REST path to avoid unnecessary request redirects Provide the access token to requests only when necessary Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
The PR is now finished. |
Yes, this code seems to working after making some changes on OpenhabCloud. |
In case your changes in your own openHAB Cloud instance fix a general bug in openHAB Cloud, please propose your fix as a PR to the openHAB Cloud project. This will benefit to other users. |
Yes, bug request has already submitted to their github link
…On 14 Feb 2021, 17:07 +0800, lolodomo ***@***.***>, wrote:
In case your changes in your own openHAB Cloud instance fix a general bug in openHAB Cloud, please propose your fix as a PR to the openHAB Cloud project. This will benefit to other users.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
…openhab#10138) Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr> Signed-off-by: John Marshall <john.marshall.au@gmail.com>
…openhab#10138) Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
…openhab#10138) Fix openhab#10055 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Please include additional credential parameters to the Bridge so that the binding can connect to remote openhab via openhabcloud.
Suggestion is given on https://community.openhab.org/t/remote-openhab-binding-access-rest-via-openhabcloud/116239/6
I appreciate you can review it and include this feature to the binding. Cheers
The text was updated successfully, but these errors were encountered: