cyberjunky / home-assistant-google_fit

:hearts: This component tracks your Google Fit activities.
MIT License
99 stars 20 forks source link

'invalid_client' on restart #26

Open coharness opened 2 years ago

coharness commented 2 years ago

I already have a couple of other Google integrations (Calendar and TTS). I added the Fitness API to my Home Assistant project on the Cloud Console. When I restart Home Assistant this is the error I get in notifications.

Error: Invalid response 401. Error: invalid_client
You will need to restart hass after fixing.
Crickus commented 2 years ago

The same issue. Updated HA to 5.2022 version from 4.2021 and integration stopped working

Crickus commented 2 years ago

Something completely wrong with authorization. Old token file gives 401 error. New file can't be created, because authorization procedure doesn't start. Standalone authorisation python script from community doesn't accept the code returned by Google. Looks like oath2 procedure has changed again or something

Crickus commented 2 years ago

Did some investigation about the problem. Old token files was made with oath2 credential type "Desktop". Home Assistant gives 401. Error: invalid_client error for this type of tokens now. New tokens of this type could be obtained, but can't be used with Home Assistant. Due to installation manual on this git you should make oath2 credential with type "TV and Limited Input". This credentials can't be obtained due to new Google security policy. Add-on gives 400: invalid_request error with "redirect_uri: urn:ietf:wg:oauth:2.0:oob" message. Could author repair authentication procedure of the component, please?

weesteev commented 2 years ago

Any movement on this one, still nothing for 2022.6.5. Integration installs ok but sign in fails with the same 401 error for me.

tomhash2 commented 2 years ago

I confirm that neither "Desktop" nor "TV and Limited Input" credential type does not wok.

cyberjunky commented 2 years ago

Can you try if downgrading to 1.0.5 helps? That uses older (very old) oauth2 and google api's package. Trying to reproduce this, but didn't succeed yet.

tomhash2 commented 2 years ago

So now, with "TV and Limited Input", I have:

Error: Invalid response 400. Error: invalid_scope You will need to restart hass after fixing.

This is related to changes Google made to API: https://github.com/vmanuel/hacs-google-fit/issues/13 https://github.com/vmanuel/hacs-google-fit/issues/15 https://support.google.com/cloud/answer/9110914#restricted-scopes&zippy=%2Cgmail-drive-and-google-fit-apis

tomhash2 commented 2 years ago

Best method for dealing with "invalid_scope" is: https://github.com/IvanVojtko/googlefit-homeassistant/issues/10

AFMHARoma commented 2 years ago

Best method for dealing with "invalid_scope" is: IvanVojtko/googlefit-homeassistant#10

Getting token file is ok, but error while decoding to utf8: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

Script saves token in strange format, which is not exactly a bytestring.

Crickus commented 2 years ago

I did some testing today. All types of credentials except "TV and Limited Input" gives 401 invalid_client error. "TV and Limited Input" gives 400 invalid_scope error. I tried different version of this integration 1.0.2-1.0.7 with no luck. It doesn't matter do you have previously generated token file or not. Integration ignores old files (from previous HA version) and new ones (generated with different versions of get_credential script).

Andrewdlec commented 2 years ago

Are there any updates you can provide on this issue? I recently came across your integration and am excited to get it set up, but am facing the same issue listed in this thread. I have tried changing my time zone but no luck so far. Thanks!

Crickus commented 2 years ago

I managed to fix invalid scope error with deleting heart_rate and sleep scopes from sensor.py. After that I just changed time zone and token was received. I know that @cyberjunky got correct scopes list from https://developers.google.com/identity/protocols/oauth2/scopes#fitness But it's not work normally with authorization string for some reason изображение

demoneto commented 2 years ago

I managed to fix invalid scope error with deleting heart_rate and sleep scopes from sensor.py. After that I just changed time zone and token was received. I know that @cyberjunky got correct scopes list from https://developers.google.com/identity/protocols/oauth2/scopes#fitness But it's not work normally with authorization string for some reason изображение

Thanks. It worked out.

Andrewdlec commented 2 years ago

I managed to fix invalid scope error with deleting heart_rate and sleep scopes from sensor.py. After that I just changed time zone and token was received. I know that @cyberjunky got correct scopes list from https://developers.google.com/identity/protocols/oauth2/scopes#fitness But it's not work normally with authorization string for some reason изображение

Dang. I was really hoping this would work. I made the change. Set my timezone to GMT no daylight savings and rebooted. Same problem as before.

xeor commented 2 years ago

This plugin is currently broken on all new installs, but removing those 2 scopes and temp-timezone seams to work.. Are those two scopes really needed? Or is removing them a temporary fix that just waits to break because google deprecates something?

Andrewdlec commented 2 years ago

I've tried auth with a Web client ID and a Desktop client ID. I've removed the two scopes, changed my time zone and rebooted multiple times. No luck here.

cyberjunky commented 2 years ago

The two scopes are valid scopes and have same auth requirements as the others, so not sure what the issue is yet... I guess all need to be rewritten to use newer > v1 API

sam2332 commented 1 year ago

can we revert the breaking changes or is this plugin dead?

weesteev commented 1 year ago

I haven't found a version that this works with and it doesn't seem like anyone wants to try and fix this either which is a shame!

cyberjunky commented 1 year ago

Install visual studio add-on, open it, open file 'config/custom_components/google_fit/sensor.py' remove the lines above, restart HA, and you know it... if you can edit yaml file, you can do this too, it's no rocketscience you know..

Ties1208 commented 1 year ago

I have the same issue. And i did delete the 2 lines at the scopes in the sensor.py file but it still has the same error... is there an other solution?