core: HydroQuebec platform fails to login with new site

Home Assistant release with the issue:

Home Assistant 0.99.3 Frontend version: 20190919.1 - latest

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Hass.io 189 RaspberryPi 3B+

Integration:

https://www.home-assistant.io/integrations/hydroquebec/

Description of problem:

As of October 9th 2019, the login page of HydroQuebec was changed. It now seems to uses OAUTH. Also note that once you login they ask you to confirm your email and this makes your previous login ID invalid. I’ve tried to change it in my Home Assistant, but it did not fix the issue. I’ve reviewed the code and it does not seem to handle OAuth either way.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

 - platform: hydroquebec
   username: !secret hydro_user
   password: !secret hydro_password
   contract: !secret hydro_account
   scan_interval: 8640
   monitored_variables:
    - balance
    - period_total_bill
    - period_length
    - period_total_days
    - period_mean_daily_bill
    - period_mean_daily_consumption
    - period_total_consumption
    - period_lower_price_consumption
    - period_higher_price_consumption
    - period_average_temperature
    - yesterday_total_consumption
    - yesterday_lower_price_consumption
    - yesterday_higher_price_consumption
    - yesterday_average_temperature

Traceback (if applicable):


Additional information:

This is the raw URL where the login link now redirects.

https://connexion.hydroquebec.com/hqam/XUI/?realm=/clients&locale=fr&goto=https://connexion.hydroquebec.com:443/hqam/oauth2/authorize?response_type%3Did_token%2520token%26client_id%3DMF_I33468f56-eff7-4ad8-9363-cdc737bb405b%26state%3DPm90VKanFrhmd1maMVLJG014Jzh2QIdJGuBw9pwH%253B%25257B%252522state%252522%25253A%252522%25257B%25255C%252522url%25255C%252522%25253A%25255C%252522%25252Fportail%25252Ffr%25252Fgroup%25252Fclientele%25252Fgerer-mon-compte%25255C%252522%25257D%252522%25252C%252522stateStore%252522%25253A%252522url%252522%25257D%26redirect_uri%3Dhttps%253A%252F%252Fsession.hydroquebec.com%252Foauth2%252Fcallback%26scope%3Dopenid%2520profile%2520email%26nonce%3DPm90VKanFrhmd1maMVLJG014Jzh2QIdJGuBw9pwH%26locale%3Dfr#login/

After capturing the login page URL and unencoding it a few times, we can see the new URL parameters.

https://connexion.hydroquebec.com/hqam/XUI/?realm=/clients&locale=fr&goto=https://connexion.hydroquebec.com:443/hqam/oauth2/authorize?response_type=id_token token&client_id=MF_I33468f56-eff7-4ad8-9363-cdc737bb405b&state=Pm90VKanFrhmd1maMVLJG014Jzh2QIdJGuBw9pwH;{"state":"{\"url\":\"/portail/fr/group/clientele/gerer-mon-compte\"}","stateStore":"url"}&redirect_uri=https://session.hydroquebec.com/oauth2/callback&scope=openid profile email&nonce=Pm90VKanFrhmd1maMVLJG014Jzh2QIdJGuBw9pwH&locale=fr#login/

The logs only report failing to use the login page without more detail.

2019-10-09 15:14:09 ERROR (MainThread) [homeassistant.components.hydroquebec.sensor] Error on receive last Hydroquebec data: Can not connect to login page

Couldn’t find anything else. I dug into the client code a bit and it seems that this is where the exception is thrown.

https://github.com/titilambert/pyhydroquebec/blob/master/pyhydroquebec/client.py#L79

Once through the redirect, the form does not have the right name anymore either. The username and password fields have also changed.

<form action="" method="post" class="form login" data-stage="LDAP1">

snip

<input type="text" id="idToken1" name="callback_0" value="" data-validator="required" required="" data-validator-event="keyup" class="form-control input-lg" autofocus="" data-kwimpalastatus="alive" data-kwimpalaid="1570653067956-4" style="background-color: rgb(255, 255, 204); color: rgb(49, 49, 49);">

snip snip

<input type="password" id="idToken2" name="callback_1" class="password-input form-control input-lg" value="" data-validator="required" required="" data-validator-event="keyup" data-kwimpalastatus="alive" data-kwimpalaid="1570653067956-3" style="background-color: rgb(255, 255, 204); color: rgb(49, 49, 49);">

snip

<input id="loginButton_0" name="callback_2" type="submit" role="button" index="0" value="Ouvrir une session" class="btn btn-lg btn-block btn-uppercase btn-primary">

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Please use English when posting.

@balloob I think we should remove the Hydroquebec integration from Home Assistant. Message for users: I’m working on the new version of the website, and I will release a daemon to send data through MQTT.

@ThierryBegin MQTT will be easy, the difficult part is the new authentication method on their website. They are now using OpenID Connect and OAuth2. I just have to figure out how to script that (I’m trying with python-oidc) but I’m an expert with the procotol/method …

Hello, the MQTT daemon (and the Docker image) are out ! Take a look: https://github.com/titilambert/pyhydroquebec (Note: this is more beta than stable)