tipok / netatmo_energy_exporter

Netatmo Thermostat exporter for Prometheus
MIT License
5 stars 1 forks source link

oauth token flow changed (again) #7

Closed DEEJCUK closed 7 months ago

DEEJCUK commented 8 months ago

seems the plugin isnt working any more, i did some looking around the forum and see this, i tried creating a new app etc but it gives error

netatmo-energy-exporter | 2024/02/10 20:58:45 could not get homes data: could not get data: error during http request: Get "https://api.netatmo.com/api/homesdata": oauth2: "invalid_grant"

https://forum.netatmo.com/viewtopic.php?p=95644#p95644

Dec 5, 2023, 14:24 GMT+1

We just did a modification on the token retrieval process :

When you refreshed an access_token using the associated endpoint https://api.netatmo.com/oauth2/token, Netatmo servers responded with a couple of tokens : an access_token and a refresh_token. If the previous access_token was still valid, the refresh_token value was never renewed

Starting from the 04/12/2023, this behavior changed to be compliant with the recommendations of the RFC of the OAuth2 Authorization Framework (section 10.4) and improving the security of the data of our users When refreshing tokens, access_token and refresh_token values will be automatically renewed and former tokens invalidated

So, if you do not update and use the new refresh_token value when refreshing your access_token, your users will be disconnected after 3 hours and you will retrieve an “invalid_grant” error To fix it, you need to update the tokens value as soon as you get the newly generated ones

DEEJCUK commented 7 months ago

any news on if this can be fixed ?

DEEJCUK commented 7 months ago

not sure what was wrong but running in manually in docker and not in compose seems to work, so i need to work out whats going on

DEEJCUK commented 7 months ago

anyone else looking for a reason for this, its probaly due to the refresh token containing "|" (pipe) and needs to be escaped like below in docker compose --refresh-token='xxxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxx'

tipok commented 7 months ago

@DEEJCUK thank you for checking this and providing a solution. I'm glad you could figure out the issue.

daviddanko commented 4 months ago

@DEEJCUK did this stop working for you as well?

DEEJCUK commented 4 months ago

@DEEJCUK did this stop working for you as well?

it did, but as mentioned it starts working again if i quote the token in my compose file, i needed to recreate the refresh token and put that in quotes and if for some reason the container dies, i need to recreate a new token and add it and it starts working again

daviddanko commented 4 months ago

I have tried to reset the tokens and recreate the container but I am getting the following error:

2024/06/12 19:47:53 could not get homes data: could not get data: error during http request: Get "https://api.netatmo.com/api/homesdata": oauth2: "invalid_client"

My compose is like this:

netatmo_energy_exporter: container_name: netatmo_energy_exporter ports:

The refresh token I am getting is by selecting read_station and read_thermostat.

DEEJCUK commented 4 months ago

mine is similar, but im not using env vars and putting the token in the compose file, i am sure i just selected read thermostat and copied the token in but in between single quotes like below

  netatmo-energy-exporter:
    container_name: netatmo-energy-exporter
    image: ghcr.io/tipok/netatmo_energy_exporter/netatmo_energy_exporter:latest
    restart: unless-stopped
    command:
      --client-id=12*****ab
      --client-secret=cD*****e1
      --refresh-token='99******9w|xy*****22'
    ports:
      - "2112:2112"
giuliomagnifico commented 3 months ago

Same here without docker. Every 7-10 days I get the error:

Jul 11 22:45:19 DietPi netatmo_energy_exporter[164947]: 2024/07/11 22:45:19 could not get homes data: could not get data: error during http request: Get "https://api.netatmo.com/api/homesdata": oauth2: "invalid_grant"

If I generate a new token, then it works for some days.

I'm launching the exporter with these parameters:

netatmo_energy_exporter --client-id 66xxxxxba --client-secret kHxoTxxxxxxxxxY48 --refresh-token "607xxxxx467f99|d42xxxxxx9f2955ce6b7" --password ExxxxxP