leikoilja / ha-google-home

Home Assistant Google Home custom component
MIT License
434 stars 73 forks source link

Can't login - 'Error': 'BadAuthentication' #95

Closed hugostegeman closed 3 years ago

hugostegeman commented 3 years ago

hi,

I cant login with my google account. is the google username the same as your google account .......@gmail.com?

DurgNomis-drol commented 3 years ago

Yes it is, Username/Email should be janedoe@gmail.com and password should be your google password. It is though highly recommend to use an app password instead.

If you have Two Factor Authentication enabled. I think you can only use an app password. Link to app password guide

hugostegeman commented 3 years ago

Ik still cant login Screenshot_2021-03-19-12-09-51-054_io.homeassistant.companion.android.jpg

DurgNomis-drol commented 3 years ago

Can you please check the logs in Home Assistant. You can find them under Configuration and then logs. Please choose Load Full Home Assistant Logs. And past them here.

ArnyminerZ commented 3 years ago

@hugostegeman if you are using a Gmail account, try logging it without adding @gmail.com, maybe that should do the trick. Also, as @DurgNomis-drol pointed out, if you are using 2FA authentication, generate an app password.

hugostegeman commented 3 years ago

I tried it with and without @gmail.com but i still cant login. 2FA authentication also does not work. my log looks like this:

2021-03-19 13:40:28 WARNING (MainThread) [homeassistant.loader] You are using a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:28 WARNING (MainThread) [homeassistant.loader] You are using a custom integration sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:28 WARNING (MainThread) [homeassistant.loader] You are using a custom integration google_home which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:28 WARNING (MainThread) [homeassistant.loader] You are using a custom integration googlehome which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:28 WARNING (MainThread) [homeassistant.loader] No 'version' key in the manifest file for custom integration 'googlehome'. This will not be allowed in a future version of Home Assistant. Please report this to the maintainer of 'googlehome'
2021-03-19 13:40:29 ERROR (Recorder) [homeassistant.components.recorder.util] The database at //config/home-assistant_v2.db is corrupt or malformed.
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 168, in validate_sqlite_database
run_checks_on_open_db(dbpath, conn.cursor(), db_integrity_check)
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 179, in run_checks_on_open_db
sanity_check_passed = basic_sanity_check(cursor)
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 157, in basic_sanity_check
cursor.execute(f"SELECT * FROM {table} LIMIT 1;") # nosec # not injection
sqlite3.OperationalError: no such table: states
2021-03-19 13:40:29 ERROR (Recorder) [homeassistant.components.recorder.util] The system will rename the corrupt database file //config/home-assistant_v2.db to //config/home-assistant_v2.db.corrupt.2021-03-19T12:40:29.350868+00:00 in order to allow startup to proceed
2021-03-19 13:40:29 WARNING (MainThread) [homeassistant.components.http] The 'base_url' option is deprecated, please remove it from your configuration
2021-03-19 13:40:33 WARNING (MainThread) [homeassistant.loader] You are using a custom integration afvalbeheer which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:33 ERROR (SyncWorker_5) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:41 WARNING (MainThread) [homeassistant.loader] You are using a custom integration saver which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:41 WARNING (MainThread) [homeassistant.loader] You are using a custom integration nodered which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:45 ERROR (MainThread) [homeassistant.components.wled] Error fetching wled data: Invalid response from API: Error occurred while communicating with WLED device at 192.168.2.24
2021-03-19 13:40:45 WARNING (MainThread) [homeassistant.config_entries] Config entry 'mengpaneel' for wled integration not ready yet. Retrying in background
2021-03-19 13:40:49 ERROR (SyncWorker_0) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_5) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_4) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_2) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_7) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_0) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_3) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_10) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_2) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_6) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
2021-03-19 13:40:49 ERROR (SyncWorker_0) [pymodbus.client.sync] [Errno 2] could not open port /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0'
DurgNomis-drol commented 3 years ago

Which version of Home Assistant are you using?

Please try to remove it and reinstalled it again. It seems there is an issue with its name here:

2021-03-19 13:40:28 WARNING (MainThread) [homeassistant.loader] You are using a custom integration googlehome which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-19 13:40:28 WARNING (MainThread) [homeassistant.loader] No 'version' key in the manifest file for custom integration 'googlehome'. This will not be allowed in a future version of Home Assistant. Please report this to the maintainer of 'googlehome' <- Problem here. Is name should be google_home.

Also please use code blocks when embedding logs. Markdown Guide

hugostegeman commented 3 years ago

Im running core version 2021.3.4 and supervisor version 2021.3.6 After reinstall I get a config error:

google

DurgNomis-drol commented 3 years ago

@hugostegeman The integration is not named googlehome, but google_home. The underscore is important. Are you installing it through HACS? If so please uninstall it and then remove the repository in HACS and re-add it and try installing it again.

hugostegeman commented 3 years ago

I installed it by using hacs and even after removing en reinstalling i cant login. Can it have something to do with the country rules from google or something im from NL? maybe manuel install of the intergration can help?

DurgNomis-drol commented 3 years ago

I don't think it matters which country you are in as long as the Google sells it devices in that country it should be supported.

You can try, but i doubt it will change any thing as installing through HACS always gives you the latest version.

Can you please try adding this to your configuration.yaml file:

logger:
  default: info
  logs:
    # log level for mielelogic_laundry
     custom_components.google_home: debug

And then post back the logs.

This will enabled a lot more information in the logs and will give os a clearer understanding of why it does not work.

WRLPDZ commented 3 years ago

Hi, Same problem. Already try with as login: user_name, full email as password: app token, master token, password to account

Logger set to:

logger:
  default: debug
  logs:
    # log level for mielelogic_laundry
     custom_components.google_home: debug

In logs only:

2021-03-20 19:09:44 ERROR (SyncWorker_16) [glocaltokens.client] [!] Could not get master token.
2021-03-20 19:09:44 ERROR (MainThread) [custom_components.google_home]
DurgNomis-drol commented 3 years ago

@WRLPDZ

When have you installed this integration?

Can you also add:

logger:
  default: info
  logs:
     custom_components.google_home: debug
     glocaltokens: debug <- Add this line

This will enable logs for the underlaying package glocaltokens.

EDIT: Also please use code blocks when pasting your log into the issue 😄

WRLPDZ commented 3 years ago

Still the same. Debug level changed.

2021-03-21 14:33:10 ERROR (SyncWorker_48) [glocaltokens.client] [!] Could not get master token.
2021-03-21 14:33:10 ERROR (MainThread) [custom_components.google_home]
DurgNomis-drol commented 3 years ago

@ArnyminerZ @leikoilja Any ideas on what could cause this? Besides not using the latest version, where it should have been fixed? I think we would need more information to know exactly why this is happening, if this problem have indeed risen again 🤔

WRLPDZ commented 3 years ago

Core Version core-2021.3.4

Supervisor Version supervisor-2021.03.6

logger: default: debug logs: custom_components.google_home: debug glocaltokens: debug

Nothing more is showing in logs: 2021-03-21 15:22:35 ERROR (SyncWorker_40) [glocaltokens.client] [!] Could not get master token. 2021-03-21 15:22:35 ERROR (MainThread) [custom_components.google_home]

I'm trying to use this because Drakulix/googlehome not showing me correct values but it's connected.

DurgNomis-drol commented 3 years ago

@WRLPDZ Can you please remove Drakulix/googlehome's integration and restart just to make sure that it is not effecting this integration. It is important that you remove both the files and how it was installed, if in configuration.yaml then remove it from here, or if via config flow, remove it from there before deleting the files. 😄 And then remove this integration and re add it again. And remember to clear browser cache.

WRLPDZ commented 3 years ago

All integrations corelated wit google home uninstalled. Host restarted. Browser cache cleared. ha-google-home installed again. Result the same. For now I will pass.

ArnyminerZ commented 3 years ago

I'm pretty sure there's an issue with @hugostegeman Home Assistant's database, and maybe that's the issue, but since @WRLPDZ has the same issue, maybe there's something more there...

Also, @WRLPDZ are you sure there aren't any more logs regarding the integration in your Home Assistant's register?

@DurgNomis-drol @leikoilja maybe we should add more debugging to glocaltokens just in case something like this happens. At debug level, so it doesn't bother normally, but more info should be provided. Will open an issue there and work on it ASAP. Then we may update ha-google-home's dependency version, and take further look.

leikoilja commented 3 years ago

Great call, @ArnyminerZ, thank you! 💥
I am also adding an issue here to include more documentation helpers for people who open issues to provide more info that will help us resolve issues such as in a feature

cs42 commented 3 years ago

I have the same issue. Just installed this via HACS, but can't log in. In log I only see:

2021-03-22 10:48:13 ERROR (SyncWorker_1) [glocaltokens.client] [!] Could not get master token.
2021-03-22 10:48:13 ERROR (MainThread) [custom_components.google_home]

I'm too using 2FA with an app password specific for this extension. Further I've configured google assistant without nabu casa.

ArnyminerZ commented 3 years ago

Hi, @cs42, thank you for the information. We are currently working on this issue, you can follow the progress at glocaltokens#48.

Also, please, use code blocks for logs, not blockquotes. 😇

leikoilja commented 3 years ago

@cs42, @bacco007, there is now a new release of the integration. Please upgrade to 1.0.1 using HACS. Also make sure you have the logger enabled in your configuration.yaml:

logger:
  default: info
  logs:
    custom_components.google_home: debug

That will now print much more elaborate logs. Please post them here (IMPORTANT make sure not to paste your sensitive info here as master_token or login). These elaborate logs (paste as code block) will help us get a better understanding why you are not able to login

cs42 commented 3 years ago

Here are the logs:

2021-03-25 11:14:35 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2021-03-25 11:14:35 DEBUG (MainThread) [glocaltokens.client] Set self username to "c******************", password to "f***************", master_token to "" and android_id to
2021-03-25 11:14:35 DEBUG (MainThread) [glocaltokens.client] Set self access_token, homegraph, access_token_date and homegraph_date to None
2021-03-25 11:14:35 DEBUG (SyncWorker_20) [glocaltokens.client] There is not any stored master_token, logging in...
2021-03-25 11:14:35 DEBUG (SyncWorker_20) [glocaltokens.client] There is not any stored android_id, generating a new one
2021-03-25 11:14:35 DEBUG (SyncWorker_20) [glocaltokens.client] Generating mac...
2021-03-25 11:14:35 DEBUG (SyncWorker_20) [glocaltokens.client] Generated mac: 525CFDC290AA48
2021-03-25 11:14:36 ERROR (SyncWorker_20) [glocaltokens.client] [!] Could not get master token.
2021-03-25 11:14:36 DEBUG (SyncWorker_20) [glocaltokens.client] Request response: {'Error': 'BadAuthentication'}

I have a 2FA setup and created a new app password for this test.

Edo78 commented 3 years ago

I was watching this because I was experiencing the very same issue. I have a 2FA and I can't login with my username and the generated app password.

I just updated to 1.0.1, add the logger to the config and now I can login and I can't understand why.

If I can provide any more info or if you need any tests at all feel free to ask and I'll be glad to help

brianhanifin commented 3 years ago

ha-google-home 1.01

Home Assistant OS 5.12


Here's my log to add to the fire. ;) I am trying to login using an app password.

2021-03-25 08:42:35 WARNING (MainThread) [homeassistant.loader] You are using a custom integration google_home which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-03-25 08:42:35 INFO (SyncWorker_19) [homeassistant.util.package] Attempting install of glocaltokens==0.2.6
2021-03-25 08:43:15 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2021-03-25 08:43:15 DEBUG (MainThread) [glocaltokens.client] Set self username to "b******************", password to "g***************", master_token to "" and android_id to 
2021-03-25 08:43:15 DEBUG (MainThread) [glocaltokens.client] Set self access_token, homegraph, access_token_date and homegraph_date to None
2021-03-25 08:43:15 DEBUG (SyncWorker_25) [glocaltokens.client] There is not any stored master_token, logging in...
2021-03-25 08:43:15 DEBUG (SyncWorker_25) [glocaltokens.client] There is not any stored android_id, generating a new one
2021-03-25 08:43:15 DEBUG (SyncWorker_25) [glocaltokens.client] Generating mac...
2021-03-25 08:43:15 DEBUG (SyncWorker_25) [glocaltokens.client] Generated mac: E0400A08AB5949
2021-03-25 08:43:15 ERROR (SyncWorker_25) [glocaltokens.client] [!] Could not get master token.
2021-03-25 08:43:15 DEBUG (SyncWorker_25) [glocaltokens.client] Request response: {'Error': 'BadAuthentication'}
2021-03-25 08:43:15 ERROR (MainThread) [custom_components.google_home] 

For good measure I also deleted yesterday's app password, and generated a new one.

2021-03-25 08:50:14 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2021-03-25 08:50:14 DEBUG (MainThread) [glocaltokens.client] Set self username to "b******************", password to "n***************", master_token to "" and android_id to 
2021-03-25 08:50:14 DEBUG (MainThread) [glocaltokens.client] Set self access_token, homegraph, access_token_date and homegraph_date to None
2021-03-25 08:50:14 DEBUG (SyncWorker_17) [glocaltokens.client] There is not any stored master_token, logging in...
2021-03-25 08:50:14 DEBUG (SyncWorker_17) [glocaltokens.client] There is not any stored android_id, generating a new one
2021-03-25 08:50:14 DEBUG (SyncWorker_17) [glocaltokens.client] Generating mac...
2021-03-25 08:50:14 DEBUG (SyncWorker_17) [glocaltokens.client] Generated mac: 33FF090A894B45
2021-03-25 08:50:14 ERROR (SyncWorker_17) [glocaltokens.client] [!] Could not get master token.
2021-03-25 08:50:14 DEBUG (SyncWorker_17) [glocaltokens.client] Request response: {'Error': 'BadAuthentication'}
2021-03-25 08:50:14 ERROR (MainThread) [custom_components.google_home] 
brianhanifin commented 3 years ago

Related logging tips:

notherealmarco commented 3 years ago

I'm having the same issue

leikoilja commented 3 years ago

Hey guys, can we try something out? I actually think it has nothing to do with google accounts themself but with the dependency libraries used. We have seen BadAuthentication before on some versions of requests library that are used under the hood. It might be that some other integrations or packages that you use in parallel with Google Home are enforcing different (lower) version of the requests library. @DurgNomis-drol, I know you are more expert in that field. What was the good way to see the version of requests installed in the HA setup? 🤔 😅

DurgNomis-drol commented 3 years ago

You can check which version you have installed by running pIp show package_name in the command line in the docker container of HA(how to get to the docker container check docs).

The important packages is requests,urllib3,chardet and gpsoauth. The problem is caused by a bug on the Google servers in how urllib3 have implemented SNI support. It should have been solved, but as @leikoilja states, if some other things are forcing a wrong version, this bug will show up.

leikoilja commented 3 years ago

Can someone who encounters BadAuthentication post here the output of (please see @DurgNomis-drol message on how to get to the docker container where to run this command):

bash-5.0# pip freeze | grep 'requests\|glocaltokens\|urllib3\|chardet\|gpsoauth'
cchardet==2.1.7
chardet==3.0.4
glocaltokens==0.2.6
gpsoauth==0.4.3
requests==2.25.1
requests-file==1.5.1
requests-futures==1.0.0
requests-oauth==0.4.1
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
urllib3==1.26.3

(that's example of mine)

cs42 commented 3 years ago

here's my output

pip freeze | grep 'requests\|glocaltokens\|urllib3\|chardet\|gpsoauth'
chardet==3.0.4
glocaltokens==0.2.6
gpsoauth==0.4.3
requests==2.25.1
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
urllib3==1.25.10

urllib differs, so here are the details for it

python3 -m pip show urllib3
Name: urllib3
Version: 1.25.10
Summary: HTTP library with thread-safe connection pooling, file post, and more.
Home-page: https://urllib3.readthedocs.io/
Author: Andrey Petrov
Author-email: andrey.petrov@shazow.net
License: MIT
Location: /srv/homeassistant/lib/python3.8/site-packages
Requires:
Required-by: synologydsm-api, requests, python-synology, botocore

My homeassistant installation is a venv one and is using Python 3.8.5, if that matters.

DurgNomis-drol commented 3 years ago

@cs42

Can you please try upgrading urllib3 to the same versions as @leikoilja. By running pip install urllib3==1.26.3 and try to login again. Remember to restart. 😁

cs42 commented 3 years ago

I just did :-D, but it didn't help :-(

Same problem as before

2021-03-26 08:34:15 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2021-03-26 08:34:15 DEBUG (MainThread) [glocaltokens.client] Set self username to "c******************", password to "u***************", master_token to "" and android_id to
2021-03-26 08:34:15 DEBUG (MainThread) [glocaltokens.client] Set self access_token, homegraph, access_token_date and homegraph_date to None
2021-03-26 08:34:15 DEBUG (SyncWorker_24) [glocaltokens.client] There is not any stored master_token, logging in...
2021-03-26 08:34:15 DEBUG (SyncWorker_24) [glocaltokens.client] There is not any stored android_id, generating a new one
2021-03-26 08:34:15 DEBUG (SyncWorker_24) [glocaltokens.client] Generating mac...
2021-03-26 08:34:15 DEBUG (SyncWorker_24) [glocaltokens.client] Generated mac: 9DE38201B51C4C
2021-03-26 08:34:15 ERROR (SyncWorker_24) [glocaltokens.client] [!] Could not get master token.
2021-03-26 08:34:15 DEBUG (SyncWorker_24) [glocaltokens.client] Request response: {'Error': 'BadAuthentication'}
2021-03-26 08:34:15 ERROR (MainThread) [custom_components.google_home]

Packages are now (oh, I just see it's urllib 1.26.4 - latest one):

pip freeze | grep 'requests\|glocaltokens\|urllib3\|chardet\|gpsoauth'
chardet==3.0.4
glocaltokens==0.2.6
gpsoauth==0.4.3
requests==2.25.1
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
urllib3==1.26.4
cs42 commented 3 years ago

Nope, doesn't work with urllib3==1.26.3 as well.

nckslater commented 3 years ago

Ik still cant login Screenshot_2021-03-19-12-09-51-054_io.homeassistant.companion.android.jpg

I'm getting the same issue.

In the logs:

Logger: custom_components.google_home Source: custom_components/google_home/config_flow.py:97 Integration: Google Home (documentation, issues) First occurred: 16:57:03 (4 occurrences) Last logged: 16:59:42

and

`Logger: glocaltokens.client Source: /usr/local/lib/python3.8/site-packages/glocaltokens/client.py:201 First occurred: 16:57:03 (4 occurrences) Last logged: 16:59:42

[!] Could not get master token.`

stboch commented 3 years ago

When I run a script on Home-Assistant's python to get the master token, it works. Not sure what is happening to cause it to generate the issue with urllib3 all the versions are correct of gpsoauth and urllib3

leikoilja commented 3 years ago

Uhhh, there is some deep-buried issue here that we need to solve. The worst thing is that we can't replicate it yet, cause for some of us it works as expected, for others - we see a bad authentication error.

I don't have many good ideas on how to solve it yet, but here are some thoughts... Can someone with the issue help replicate it in the isolation? We need to get the same error in isolation (let's say using Raspberry Pi 3/4) with minimum configurations (preferably clean setup with only Google Home integration installed) and get to the point where the same issue occurs? Then posting here as much configs as possible (HA version, pip packages and dependencies versions), so I could try replicating it locally following the exact same setup/versions you would have.

stboch commented 3 years ago

I know its not optimal but is there a way to support adding the master token instead of the account credentials, i'm not sure how long the master token is good for vs the the account credentials, might be a work around option.

DurgNomis-drol commented 3 years ago

Master token is very very long lived. A couple of years or so. If not more.

leikoilja commented 3 years ago

I'm pretty sure master token is meant to be "forever" lived. But that is a good idea, @stboch. Thank you 💥
Our underlying dependency glocaltokens supports receiving master_token alone, so we should be able to add that feature relatively effortlessly.

I was thinking we should spend some effort making a better config flow where one can edit the existing config and during initial setup allow users options like 'username', 'password' as well as 'master_token` and 'android_id' specifications. What do you guys think, @KapJI, @DurgNomis-drol, @ArnyminerZ?

KapJI commented 3 years ago

If 2FA is not used, you need to enable "Less secure apps" as well: https://github.com/rithvikvibhu/GHLocalApi/issues/54#issuecomment-674654337

Also can you guys try to use this gist directly? Are you still getting the same error? Can you try to downgrade requests and gpsoauth libs?

Regarding making the component more configurable, it's a good idea as well. Especially if it helps someone.

stboch commented 3 years ago

@KapJI that's is basically the script I ran on the underlying ha container, and it ran fine with all the python packages provided, not sure why when just asynchronously via home-assistant itself it fails.

Golab commented 3 years ago

Any news update? I have the same problem

KapJI commented 3 years ago

@stboch what if you go the step further and try to use glocaltokens library?

Something like this: https://github.com/leikoilja/glocaltokens/blob/master/example/get_tokens.py

stboch commented 3 years ago

@KapJI sorry should have looked closer I used the glocaltokens implementation of get_tokens.py not the other googleapi one.

but yes it worked no issues was very odd. Not much debugging done in gpsoauth to see if HA is calling something different about urllib3 as part of the environment...

leikoilja commented 3 years ago

I have been trying to look around and the topic of Bad Authentication has been there for many people in a very random order (see 1, 2, 3). @cs42, can you please try downgrading requests library by running pip install requests==2.23.0? Please don't forget to restart after and show us pip freeze | grep 'requests\|glocaltokens\|urllib3\|chardet\|gpsoauth' after the restart.

cs42 commented 3 years ago

This still doesn't work.

$ pip freeze | grep 'requests\|glocaltokens\|urllib3\|chardet\|gpsoauth'
chardet==3.0.4
glocaltokens==0.2.6
gpsoauth==0.4.3
requests==2.23.0
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
urllib3==1.25.11
DurgNomis-drol commented 3 years ago

@leikoilja If we can implement it in a way that you need to push a button or so to enable advanced login, then i think it is a good work around for now until we can get to the bottom of this. 😄

As @leikoilja said somewhere. We need to find a way to replicate it locally and repeatably before we can find a solution.

My best guess is that it occurs in the gpsoauth package and that we should isolate it there and do some tests. It could have something to do with how we generate an android id/mac address. We need to spend sometime understand that we generate something that is valid. I read inside-android-play-services-magic. It describes how we actually authenticate with Google. I believe that there need to be something speciel in the android id/mac address for it to work. But i am not an expert on this at all. But this could possibly be explanation for why it occur at random. If some one with better knowledge of this have any idea, please correct me if there is something that I don't known.

leikoilja commented 3 years ago

I agree, we probs need to remedy the issue rn by introducing master_token field in config_flow as a workaround until we can replicate and solve the issue at hand.

@DurgNomis-drol, i had an idea that android id might be the issue and I have locally tried to use one of the android id mentioned above as BadAuthentication with no results. I was still able to authenticate and it all worked fine for me.

DurgNomis-drol commented 3 years ago

@leikoilja Dammit, i though i got closer to understanding it 😞 If we can get everyone having this issue to try and fetch it directly from gpsoauth or maybe even glocaltokens to see if it is, as @stboch mentions, a problem with HA.