kpoppel / homeassistant-novafos

Homeassistant wrapper around the Novafos KMD water metering data warehouse.
Apache License 2.0
10 stars 3 forks source link

Not working anymore #5

Closed Sdahl1234 closed 2 years ago

Sdahl1234 commented 2 years ago

Seems KMD has change something..

MinForsyning Løsningen er desværre ikke tilgængelig på nuværende tidspunkt. Prøv venligst igen senere. 403: adgang forbudt

Does it work for anyone else?

kpoppel commented 2 years ago

I believe I have the same issue here. Logging in using the browser and using email I got prompted to change the password. I seems the password rules changed. Updating this and reinstalling the plugin there seems to be a change in the login procedure as well. For now please disable the plugin while I look into this.


    result_json = result.json()
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 917, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: [Errno Expecting value] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>```
kpoppel commented 2 years ago

I loked into this a little more. The authorization has changed from a simple user/pass challenge to something "Openiddict". The user/pass is used together with a nonce and other stuff, results in a "code"+"code_challenge", wich is then claimed to get a Bearer token. Unfortunately this token only lasts one hour and neets the code-challenge to run again to be renewed. So there is no way to even be logged in and just renew the token. I have no idea whatsoever how to solve this issue in a nice way outside:

  1. Mimick what happens on the website - though the "nonce" etc. is generated upon loading the login page. It is simply part of the HTML retrieved.
  2. Write Novafos to implement some sort of application API like the electricity metering datahub has it.
kpoppel commented 2 years ago

They have changed from a simple user/password challenge to get the Bearer token to OpenID (oicd endpoint) which is a layer on top of OAuth2. This incurs a lot of exchanges and redirects to KMD and so on. This will take some time to figure out as I am by no means knowledgable in this area.

kpoppel commented 2 years ago

Good news! I am now able to login using the OIDC method and can retrieve data from the REST endpoint. I hope during tomorrow to be able to update the plugin with this new authentication method which is rather long winded.

kpoppel commented 2 years ago

Release v2.0.0 fixes this issue.