[UPDATE]: After inspected the login part between cloud and openhab. It is doing OAuth. Finally, I got the auth code and call auth/token to exchange access token.
Background:
- OH3
- Raspberry 4
- openhabian
- cloud connector
- private openHAB cloud
I have a local openHAB server to control my home IoT devices.
And it has been installed openHAB Cloud Connector to connect my own openHAB cloud for remote access. I want to build a CMS/APP to manage my openHAB devices through openHAB restful API.
Problem:
If I use “Basic authentication” (Endpoint: openHAB cloud, cloud account), it only can access basic APIs such as “/rest/sitemaps”, “/rest/items”.
If I try to access “/rest/addones”, it responses with “{“error”:{“message”:“Authentication required”,“http-code”:401}}”
For example:
curl -X GET "https://mycloud-domain.com/rest/addons" -H "Accept: application/json" -H "Authorization: Basic a2VudKVzdGZvdmpvEkBnbWCpdC5jd20da3Rob21lMjAyMg=="
After Research:
I found rlkoshakIt
has pointed out that there are two-layer authorizations in other post
e.g:
curl. → myopenhab.org(or private cloud) → openHAB
And then I try to get bearer token from browser (after login cloud and local openHAB) and then combine with basic authentication to call openHAB api, it works!
For example:
curl -X GET "https://mycloud-domain.com/rest/addons" -H "Accept: application/json" -H "Authorization: Basic a2VudKVzdGZvdmpvEkBnbWCpdC5jd20da3Rob21lMjAyMg==" -H "Accept: application/json" -H "X-OPENHAB-TOKEN:eyJraWQ..."
Question 1:
Anyone has idea to implement OAuth or other proper way to get access token?
Question 2:
I can see there is “auth/token” api in API Explorer but how can I implement it?
What is the value or how to get these value for grant_type, code, redirect_url, client_id, refreesh_token and code_verifier?
Thanks for reading my post!