Feller-AG / wiser-api

MIT License
15 stars 1 forks source link

how to get an authorization token? #1

Closed Villagio88 closed 2 years ago

Villagio88 commented 2 years ago

I've been an enthusiastic Wiser user for half a year. Now I wanted to use the newly created API interface and link my Wiser system to Homebridge. Unfortunately, I always fail with authentication. Can you help me how to get my authorization token? I tried to follow the FellerAG/Wiser Tutorial, but unfortunately I failed.

woodworm commented 2 years ago

Actually it should all be explained here.

But there is a way to bypass the whole thing.

  1. go to the "settings" web page.
  2. click tab "Admin"
  3. enter 👤 Username and 🗝 Current password
  4. remove flag ⚠️ Lock access
  5. press "Save" button

after that no token is needed.

Villagio88 commented 2 years ago

Thank you very much. I changed the described details. Unfortunately, I still fail with authentication and get this Error:

TypeError: loads is not iterable
    at /usr/local/lib/node_modules/@hansfriedrich/homebridge-feller-wiser/src/platform.ts:64:26
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2/2/2022, 4:02:27 PM] [@hansfriedrich/homebridge-feller-wiser] Child bridge process ended
[2/2/2022, 4:02:27 PM] [@hansfriedrich/homebridge-feller-wiser] Process Ended. Code: 1, Signal: null
[2/2/2022, 4:02:34 PM] [@hansfriedrich/homebridge-feller-wiser] Restarting Process...
[2/2/2022, 4:02:34 PM] [@hansfriedrich/homebridge-feller-wiser] Launched child bridge with PID 33096
[2/2/2022, 4:02:34 PM] Registering platform '@hansfriedrich/homebridge-feller-wiser.feller-wiser'
[2/2/2022, 4:02:34 PM] [@hansfriedrich/homebridge-feller-wiser] Loaded @hansfriedrich/homebridge-feller-wiser v1.0.16 child bridge successfully
[2/2/2022, 4:02:34 PM] Homebridge v1.4.0 (HAP v0.10.0) (@hansfriedrich/homebridge-feller-wiser) is running on port 38372.
[2/2/2022, 4:02:34 PM] [@hansfriedrich/homebridge-feller-wiser] error occured unauthorized user 

And this is my used code for my first load:

{
    "bridge": {
        "name": "Homebridge 189D",
        "username": "0E:A7:E5:D6:18:9D",
        "port": 51046,
        "pin": "634-88-819"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "auth": "form",
            "theme": "auto",
            "tempUnits": "c",
            "lang": "de",
            "platform": "config"
        },
        {
            "ip": "192.168.1.51",
            "platform": "feller-wiser",
            "_bridge": {
                "username": "0E:1C:DE:9E:66:16",
                "port": 38372
            },
            "data": [
                {
                    "id": 1,
                    "type": "onoff",
                    "name": "00005adf_0",
                    "device": "00005adf",
                    "channel": 0,
                    "unused": false
                }
            ]
        }
    ]
}

As far as I am not a programmer, it would be great to get tech. support to install the api correctly, I would also be happy to pay for the expenses.

woodworm commented 2 years ago

I would like to help you... but to me it looks like the problem occurs together with the homebridge-feller-wiser plugin. This project is "mega cool"!!! Unfortunately I have too little knowledge about it to help you. I would ask this question there.

Villagio88 commented 2 years ago

Feller told me to ask the question here ... they said that "Holzwurm" would help me ;-) This is my config:

{
    "bridge": {
        "name": "Homebridge 189D",
        "username": "0E:A7:E5:D6:18:9D",
        "port": 51046,
        "pin": "xxx-xx-xxx"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "ip": "192.168.1.51",
            "platform": "feller-wiser",
            "_bridge": {
                "port": 57992
            }
        }
    ],
    "disabledPlugins": []
}

As far as i can tell, i came a step closer but now I get this error:

TypeError: Cannot read properties of undefined (reading 'toUpperCase')
    at /usr/local/lib/node_modules/homebridge/src/server.ts:411:75
    at Array.forEach (<anonymous>)
    at Server.loadPlatforms (/usr/local/lib/node_modules/homebridge/src/server.ts:372:27)
    at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:159:29)

Thank you very much for your help anyway!

hansfriedrich commented 2 years ago

thanks for mentioning me and thank In my opinion the quick fix could be to use the swagger interface: down below at the footer of the µGateway's page. There the "try it" on the endpoint /api/account/claim can be used. After sending the request and pushing the blinking button, the response should contian the api key.

Note for me: maybe it could be a good idea to add this functionality to the config-ui of my plugin. Till now I haven't had the effort to do so. Now it's on the list :)

Villagio88 commented 2 years ago

thank you very much for your quick response! I'm so glad to find such helpful people. Could you pleas elaborate a bit more on how to use the swagger interface and where do I find the µGateway page?

hansfriedrich commented 2 years ago

sure. you mentioned

    {
        "ip": "192.168.1.51",
        "platform": "feller-wiser",
        "_bridge": {
            "port": 57992
        }

so I assume your wifi-device for your wiser-system has the ip 192.168.1.51. if you ask your browser for this IP address you reach the µGateway. I can't remember the process to set up the username and password for it, but I think you will be guided somehow on this page. Maybe the Feller guys know more on this. After login you can find the the link on the footer. It says Here you get an OpenAPI documentation and Live Demo of this µGateway.

woodworm commented 2 years ago

many thanks for your support hansfriedrich! hansfriedrich has already explained everything to you very well. But if you have already disabled the Lock access (first answer) , a valid token is no longer necessary. After that you can pass as token what you want... the api is open.

maybe something like this could work { "ip": "192.168.1.51", "authkey" : "cheibe zügs mit denen tokens", "platform": "feller-wiser" }

If you create your own token with "POST /api/account/claim " you will not only get access to the API, you will also create a database for this user. But I think all this is not necessary for your use case.

Villagio88 commented 2 years ago

@hansfriedrich @woodworm You guys are awesome thank your very much once again for your kind help. I was able to set an authkey with your support and implemented it in my plugin. Here my JSON configuration:

{
    "ip": "192.168.1.51",
    "username": "apiuservilla",
    "authkey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "platform": "feller-wiser"
}

In regards to your last posts this should be everything I need to run the plugin. But unfortunately the homebridge-server still gets an error:

[2/2/2022, 11:54:01 PM] Homebridge v1.4.0 (HAP v0.10.0) (Homebridge 189D) is running on port 51046.
[2/2/2022, 11:54:02 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:02 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:02 PM] [feller-wiser] error occured unauthorized user
[2/2/2022, 11:54:02 PM] TypeError: loads is not iterable
    at /usr/local/lib/node_modules/@hansfriedrich/homebridge-feller-wiser/src/platform.ts:64:26
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2/2/2022, 11:54:02 PM] Got SIGTERM, shutting down Homebridge...
[2/2/2022, 11:54:03 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:03 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:03 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:03 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:04 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:04 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:04 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:04 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:04 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:04 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:05 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:05 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:05 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:05 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:05 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:05 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:06 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:06 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:06 PM] [feller-wiser] error occured on websocket Unexpected server response: 200 ... reconnecting
[2/2/2022, 11:54:06 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:07 PM] [feller-wiser] error occured on websocket socket hang up ... reconnecting
[2/2/2022, 11:54:07 PM] [feller-wiser] websocket connetion closed with code 1006 reason:   ... reconnecting
[2/2/2022, 11:54:07 PM] [HB Supervisor] Homebridge Process Ended. Code: 143, Signal: null
[2/2/2022, 11:54:12 PM] [HB Supervisor] Restarting Homebridge...
[2/2/2022, 11:54:12 PM] [HB Supervisor] Starting Homebridge with extra flags: -I
[2/2/2022, 11:54:12 PM] [HB Supervisor] Started Homebridge v1.4.0 with PID: 53232
[2/2/2022, 11:54:12 PM] Loaded config.json with 0 accessories and 2 platforms.
[2/2/2022, 11:54:12 PM] Loaded 0 cached accessories from cachedAccessories.
[2/2/2022, 11:54:12 PM] ---
[2/2/2022, 11:54:13 PM] Loaded plugin: homebridge-config-ui-x@4.42.0
[2/2/2022, 11:54:13 PM] Registering platform 'homebridge-config-ui-x.config'
[2/2/2022, 11:54:13 PM] ---
[2/2/2022, 11:54:13 PM] Loaded plugin: @hansfriedrich/homebridge-feller-wiser@1.0.16
[2/2/2022, 11:54:13 PM] Registering platform '@hansfriedrich/homebridge-feller-wiser.feller-wiser'
[2/2/2022, 11:54:13 PM] ---
[2/2/2022, 11:54:13 PM] Loading 2 platforms...
[2/2/2022, 11:54:13 PM] [Config] Initializing config platform...
[2/2/2022, 11:54:13 PM] [Config] Running in Service Mode
[2/2/2022, 11:54:13 PM] [feller-wiser] Initializing feller-wiser platform...
Setup Payload:
X-HM://0024IQCDV67QK
Enter this code with your HomeKit app on your iOS device to pair with Homebridge:

Can you guys see the problem ?

Thank you so much ! und liebi Grüass us em Bündnerland

thomail commented 2 years ago

maybe try to delete the username in your configuration. my config looks like this:

{ "ip": "192.168.50.230", "authkey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "platform": "feller-wiser" }

if that doesnt solve your problem get a new auth token and try it again. sometimes, if I logged into wiser by feller app in between I need to get a new token, not sure why... for me the plugin from @hansfriedrich works flawlessly.

good luck und gruäss usäm thurgau

woodworm commented 2 years ago

@thomail you probably entered the user admin in the service POST /api/account/claim to get a token (secret). user admin is also used by the wiser by feller app and creates a new token for this user. Use another name and your token will not be overwritten anymore.

e.g.

POST /api/account/claim
{
  "user": "thomails_homebridge"
}
thomail commented 2 years ago

@woodworm that is exactly the case, thanks for clearing this issue!

woodworm commented 2 years ago

@Villagio88 the issue described by thomail could be the same for you.

  1. click this link image

  2. click /api/account/claim image

  3. click try it out image

  4. set user in request body and click execute image

  5. press the flashing button on the device

  6. copy your secret (token) image

  7. paste token as "authkey" 7.1 hope you have success and fun

Villagio88 commented 2 years ago

@thomail @woodworm @hansfriedrich You guys are simply awesome. I was able to get everything up and running ;-) I'm so happy !!! Thank you very much for your help.