Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 400: invalid_request #10

Open
baldachyn opened this issue Mar 19, 2022 · 11 comments
Open

Error 400: invalid_request #10

baldachyn opened this issue Mar 19, 2022 · 11 comments

Comments

@baldachyn
Copy link

After couple of days working the integration stopped providing data, log says:

google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})

while trying to re-authenticate with google, google says

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy for keeping apps secure.

I am only one experiencing this?

@nolander86
Copy link

It uses the OOB flow which has been deprecated for any new clients it looks like. https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html#disallowed-oob.

@seanmhoffman
Copy link

seanmhoffman commented May 7, 2022

The workaround that I found to this currently is available to anyone who uses Nabu Casa or has their HA install available outside of their home network via DuckDNS or some other method.

Generate Client ID & Secret:

  1. Follow the steps listed under the Generate Client ID and Client Secret section here until you reach Step 13.
  2. Set the Application type to Web Application and give this credential set a name (like Home Assistant Fit Credentials)
  3. Under the Authorized redirect URIs section, click + Add URI
  4. In the input field that appears enter the OAuth callback URL for your HA installation i.e. https://<NABU_CASA_ID>.ui.nabu.casa/auth/external/callback or https://<HOME_ASSISTANT_EXTERNAL_URL>/auth/external/callback
  5. Click Create
  6. Download the new credentials and save them as credentials.json

Generate Token:

  1. In the same directory that credentials.json is located download the updated get_credentials.py from this gist.
  2. Open get_credentials.py in a text editor and update Line 21 to your redirect url and save.
  3. Next in your terminal navigate to the directory where your files are located and run python get_credentials.py
  4. Navigate to the url generated in the terminal output.
  5. Follow the steps to authenticate.
    If you run into the Google hasn’t verified this app page, click the Advanced link and the Go to (xxxx)
  6. When you reach a white page that says Invalid state copy the Authenticate Code from the URL. It is located between the state and scope url parameters and should be prefixed with code= and end before &scope
  7. Enter the code taken from the url into the Enter the authorization code: prompt in your terminal and click Enter
  8. Copy the newly generated .google_fit.token into your HA configuration directory and restart HA.

@Unthred
Copy link

Unthred commented May 10, 2022

Worked for me thanks!

@baldachyn
Copy link
Author

Didn't work for me, though :-(
When ran get_credentials.py it printed
Traceback (most recent call last): File "C:\Users\tomas\Downloads\google fit2\get_credentials.py", line 3, in <module> from google_auth_oauthlib.flow import Flow ModuleNotFoundError: No module named 'google_auth_oauthlib'

@FirefighterRQ
Copy link

Didn't work for me, though :-(
When ran get_credentials.py it printed
Traceback (most recent call last): File "C:\Users\tomas\Downloads\google fit2\get_credentials.py", line 3, in <module> from google_auth_oauthlib.flow import Flow ModuleNotFoundError: No module named 'google_auth_oauthlib'

I get the same error when I run it

@ellite
Copy link

ellite commented Jun 17, 2022

Didn't work for me, though :-(
When ran get_credentials.py it printed
Traceback (most recent call last): File "C:\Users\tomas\Downloads\google fit2\get_credentials.py", line 3, in <module> from google_auth_oauthlib.flow import Flow ModuleNotFoundError: No module named 'google_auth_oauthlib'

I get the same error when I run it

Just run:
pip3 install google_auth_oauthlib

@fcamilleri
Copy link

fcamilleri commented Jul 6, 2022

Thanks ! It's working now, however I had to set the Application Type to 'Desktop Application' instead of 'Web Application' otherwise Google would block the auth

@IvanVojtko
Copy link
Owner

Hey @baldachyn. I updated get_credentials script but I also had to generate new credentials in google fitness API. I had to choose Desktop application, otherwise it was not working.
image
I'll update a README file.

@grandles1212
Copy link

I was able to get the token file, but when I upload it into home assistant, I get the error below. Any ideas?


Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/homeassistant/.homeassistant/custom_components/google_fit/sensor.py", line 176, in setup_platform
client = _get_client(token_file)
File "/home/homeassistant/.homeassistant/custom_components/google_fit/sensor.py", line 98, in _get_client
http = credentials.authorize(httplib2.Http())
AttributeError: 'NoneType' object has no attribute 'authorize'

@david-romero
Copy link

I was able to get the token file, but when I upload it into home assistant, I get the error below. Any ideas?

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform await asyncio.shield(task) File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/home/homeassistant/.homeassistant/custom_components/google_fit/sensor.py", line 176, in setup_platform client = _get_client(token_file) File "/home/homeassistant/.homeassistant/custom_components/google_fit/sensor.py", line 98, in _get_client http = credentials.authorize(httplib2.Http()) AttributeError: 'NoneType' object has no attribute 'authorize'

@grandles1212

I have the same issue

@kingozone
Copy link

I was able to get the token file, but when I upload it into home assistant, I get the error below. Any ideas?

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform await asyncio.shield(task) File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/home/homeassistant/.homeassistant/custom_components/google_fit/sensor.py", line 176, in setup_platform client = _get_client(token_file) File "/home/homeassistant/.homeassistant/custom_components/google_fit/sensor.py", line 98, in _get_client http = credentials.authorize(httplib2.Http()) AttributeError: 'NoneType' object has no attribute 'authorize'

I too, have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests