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

Could not get master / access token [!] #890

Open
DanielvG-IT opened this issue Jul 13, 2024 · 21 comments
Open

Could not get master / access token [!] #890

DanielvG-IT opened this issue Jul 13, 2024 · 21 comments

Comments

@DanielvG-IT
Copy link

Describe the bug

If i fill in my account details and press on "send" then i get the error:
"Username/Password is incorrect. If your Google Account has 2FA enabled, generate an app password (https://myaccount.google.com/apppasswords). If authentication still fails, please refer to https://github.com/leikoilja/ha-google-home#troubleshooting"

I tried logging in with both my application password an my real password. They both didn't work. I have 2fa enabled but when I used my real credentials, it took way longer for the error to show up (THE FIRST TIME!).

Version of the integration

If you are unsure about the version check the github release here.

v1.11.1

Logs

Logger: glocaltokens.client
Source: custom_components/google_home/api.py:75
integration: google_home (documentation, issues)
First occurred: 14:26:33 (5 events)
Last logged: 14:31:08

[!] Could not get master token.


Logger: custom_components.google_home
Source: custom_components/google_home/config_flow.py:132
integration: google_home (documentation, issues)
First occurred: 14:26:33 (5 events)
Last logged: 14:31:08

I have tried it via a docker container on a Ubuntu VM but it still fails!

image

@CoryAlbrecht
Copy link

I have this problem, too, and when running through the troubleshooting steps I was playing with that get_tokens.py script from the other person and in the def _get_android_id() I found what might be the problem.

That function checks if the lowest bit of the high byte is set or not, and if set it throws and error and cannot continue.

Change the first line of that function to

mac_int = getmac() ; print(">MAC: {0:012x}/{0:048b} {1:08b}".format(mac_int, (mac_int>>40)))

And you can see if that might be happening to you, too.

@DurgNomis-drol @leikoilja

Does glocaltokens make a similar check for a set bit in the pseudo-MAC obtained?

@CoryAlbrecht
Copy link

2024-08-01 13:02:56.070 ERROR (MainThread) [custom_components.google_home]
2024-08-01 13:03:39.652 WARNING (SyncWorker_2) [custom_components.sinope] Error code: 7ffc (None or invalid value for dfc60000), Data:(550015004102269322520a0100dfc60000070802000002fc7f19)
2024-08-01 13:03:44.809 WARNING (Recorder) [homeassistant.components.recorder.db_schema] State attributes for sensor.sm_p610_active_notification_count exceed maximum size of 16384 bytes. This can cause database performance issues; Attributes will not be stored
2024-08-01 13:03:55.862 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2024-08-01 13:03:55.862 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
2024-08-01 13:03:55.862 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "c<redacted>", password to "<redacted>", master_token to "None" and android_id to None
2024-08-01 13:03:55.863 DEBUG (SyncWorker_31) [glocaltokens.client] There is no stored master_token, logging in using username and password
2024-08-01 13:03:55.863 DEBUG (SyncWorker_31) [glocaltokens.client] There is no stored android_id, generating a new one
2024-08-01 13:03:55.863 DEBUG (SyncWorker_31) [glocaltokens.client] Generating android id...
2024-08-01 13:03:55.863 DEBUG (SyncWorker_31) [glocaltokens.client] Generated android id: b45323626d4e9787
2024-08-01 13:03:56.071 ERROR (SyncWorker_31) [glocaltokens.client] [!] Could not get master token.
2024-08-01 13:03:56.071 DEBUG (SyncWorker_31) [glocaltokens.client] Request response: {'Error': 'BadAuthentication'}
2024-08-01 13:03:56.072 ERROR (MainThread) [custom_components.google_home]

@CoryAlbrecht
Copy link

Removed the check for that bit, still couldn't get the master token.

@leikoilja
Copy link
Owner

there were numerous BadAuthentication issues previously reported see this and so far there is no consistent answer to what is causing it. Most likely it happens on google side when and how they are rejecting authentication.
What I suggest you do is get a master token instead and then use it for the integration. See this section for details on how to get the master token. Let us know if that resolves your issue

@CoryAlbrecht
Copy link

@leikoilja That's how I was trying to get the master token. I tried all those ways.

@mrussak
Copy link

mrussak commented Sep 3, 2024

I'm getting the [!] Could not get master token. as well.

If I set the debug flag to True in the script, I see the following output:

[*] Getting master token...
{'Error': 'NeedsBrowser', 'Url': 'https://accounts.google.com/signin/continue?sarp=1&scc=1&continue=https://accounts.google.com/o/android/auth?{OMITTED_FOR_PRIVACY}', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'}
[!] Could not get master token.
[*] Master token: None

[*] Getting access token...
{'Error': 'BadAuthentication'}
[!] Could not get access token.
[*] Access token: None

[*] Done.

I'm attempting to run this on a Raspberry Pi 4. It is CLI only, so no browser to try. The breph/ha-google-home_get-token docker image does not work on RPi because of the arm/V8 architecture not matching the amd64 that the image is built with.

My Google account has 2FA, but I created an app password and am attempting to use that with this script.

@leikoilja
Copy link
Owner

@mrussak, you dont need RPi to run docker image for getting master token. run it on your regular machine, get the master token (it's not changing unless you change your acc password). and then use the master token when setting up ha-google-home integration in HA

@mrussak
Copy link

mrussak commented Sep 4, 2024

Thank you @leikoilja, I tried it on my Mac locally with the docker image and that worked.

I mistakenly assumed the master token was somehow tied to my MAC address since the python code pulled that info, but I guess it's not.

Appreciate the quick reply!

@lyazide
Copy link

lyazide commented Sep 15, 2024

I have similar issue and I am not able to get it working. I get the floowing error with the docker:

[*] Getting master token...
{'Error': 'BadAuthentication'}
[!] Could not get master token.
[*] Master token: None

[*] Getting access token...
{'Error': 'BadAuthentication'}
[!] Could not get access token.
[*] Access token: None

Tried also with manual install with the same result.

@CoryAlbrecht
Copy link

I get that same error with the container method.

cory@redbarchetta[13:47:28]~$ docker run --rm -it breph/ha-google-home_get-token
Unable to find image 'breph/ha-google-home_get-token:latest' locally
latest: Pulling from breph/ha-google-home_get-token
2f088d622efd: Pull complete 
0188599e4719: Pull complete 
0c29a314dea0: Pull complete 
2f106c5bb655: Pull complete 
50a99c299447: Pull complete 
987516cbd67e: Pull complete 
Digest: sha256:03433b75c70daedb445ef1d51996ecafe070313c9e42c1cdf10e8a835b01ea1b
Status: Downloaded newer image for breph/ha-google-home_get-token:latest
what is your google mail address? (include @gmail.com): «redacted»
what is the password? (either use regular password or app password): «redacted»

[*] Getting master token...
[!] Could not get master token.
[*] Master token: None

[*] Getting access token...
[!] Could not get access token.
[*] Access token: None

[*] Done.

@TonioBDS
Copy link

TonioBDS commented Oct 4, 2024

Hello ! I use another solution than HA (Jeedom) but which uses same API to get master and access tokens to track the alarms and timers of my google homes.
I get exactly the same behavior as detailed by @mrussak :
root@debianTonio:/var/www/html/plugins/ghlocal/resources# python3 /var/www/html/plugins/ghlocal/core/class/../../resources/get_tokens_verbose.py [email protected] xxxxxxxxxxxxxx True DEBUG:glocaltokens.client:Initializing new GLocalAuthenticationTokens instance. DEBUG:glocaltokens.client:Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None DEBUG:glocaltokens.client:Set GLocalAuthenticationTokens client username to "a<redacted>", password to "<redacted>", master_token to "None" and android_id to None DEBUG:glocaltokens.client:There is no stored master_token, logging in using username and password DEBUG:glocaltokens.client:There is no stored android_id, generating a new one DEBUG:glocaltokens.client:Generating android id... DEBUG:glocaltokens.client:Generated android id: d3e233381e693276 ERROR:glocaltokens.client:[!] Could not get master token. DEBUG:glocaltokens.client:Request response: {'Error': 'NeedsBrowser', 'Url': 'https://accounts.google.com/signin/continue?sarp=1&scc=1&continue=https://accounts.google.com/o/android/auth?hl%3Den_us%26xoauth_display_name%3DAndroid%2BLogin%2BService%26source%3DAndroid%2BLogin&plt=AKgnsbu2LrQj_nFyBTUd8kjYvE55a2jPxqTSXdCi82HAU1-uhuaC_Aq04mX9j8NUBOVsD39HsHHbJ78hU7sclkEJBqYGhZ1EB4ZM0NA52Lj5nHka_r6ohFpl2Cf80p4FyokZRQ6SEt7B', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'} None

I have reported an issue on the glocaltokens repo

I was wondering if it could come from incompatibility of versions of python modules...
Anyways, please let me know if you have resolved this issue or if at least you have progressed in its investigation.
Thank you

@sriharshaguthikonda
Copy link

have the same issue

@TonioBDS
Copy link

Good to hear that I'm not the only one... I was feeling lonely !
In fact, I've installed Home Assistant to test google-home HACS repo.

in the doc it is said:
Master token Due to authentication issues with google credentials alone it may be required to get the master token separately and provide it during the setup process. This can be done using this script

But it definitely doesn't work when only email and app password is set...

If it is still working for someone, please tell us how... It's maybe due to recent google home api...
Thanks

@afs5327
Copy link

afs5327 commented Oct 14, 2024

But it definitely doesn't work when only email and app password is set...

If it is still working for someone, please tell us how... It's maybe due to recent google home api... Thanks

@TonioBDS ,
I set this up last week, and ran into the same issues it sounds like you are. The email and app password alone would not work. I then ran the script to get a "master token" and that worked, I got the master token from the script, and it was the correct character count, but it still would not work.

I then restarted the whole system I have HA running on in Proxmox, and then it took the master token on the first try. This integration has been running fine since then.

I would suggest trying to restart whatever you have HA running on, and not just restarting HA from inside the HA menus, and see if that helps.

@TonioBDS
Copy link

Thanks a lot for your feedback @afs5327, I run HA OS on a VM in my synology NAS.
I'll try the following in that order then:

  • restart the VM and retry (meaning with only email and app password)
  • try to run the script to get a master token and give it another try with the master token field filled

But I have question about that: I understood that the master token was changing periodically.
Do you confirm that or is it only linked to the app password such that it will remain OK as long as the app password does?

Or, did you find a way to automatize the master token regeneration?
Thanks again !

@afs5327
Copy link

afs5327 commented Oct 14, 2024

No problem, @TonioBDS, let me know if that sorts it out for you!
I have not had to change the master token yet, so if it does change, it lasts for more than a week.

Make sure the MT you get is exactly 233 characters.
I'm mostly a Windows guy, and this thread helped me make it from Windows.

@TonioBDS
Copy link

Hello,

For info, a full reboot did not work.
To get my master token I choose the solution to install a docker on my Synology NAS through the Container app based on image https://github.com/Brephlas/dockerfile_breph-ha-google-home_get-token.
Very simple to use : I just opened a terminal and entered the command python3 get_tokens.py and voilà !

However, for info my master token from aas_et/ to = is only 223 characters long, not 233 as mentionned above and on other forums.
Anyways it works in HA : all my devices are now detected.
I don't know how long it will last but thank you very much to all of you, you gave me the courage to try harder. It's been 15 days I was struggling with that f*** master token !

@ward0
Copy link

ward0 commented Nov 8, 2024

I had to put masterpwd on 1 single line.
I also have 223 characters.
But it worked

@CoryAlbrecht
Copy link

So I had a catastrophic crash which meant I had to rebuild my Debian server that boots from a ZFS pool that runs Docker on which I had Home Assistant. On a whim I decided to delete the old app password, something I had done 7 times previously trying to get this integration to work. Yes, I add numbers to the names of the app passwords when I re-make them to keep track of things like that.

And this time using the docker image method I was able to get a master token.

Don't ask me why, I'd done all these steps multiple times before, deleting and creating a new app password each time and all that.

Maybe I sacrificed enough chickens while rebuilding the server.

@leikoilja
Copy link
Owner

So I had a catastrophic crash which meant I had to rebuild my Debian server that boots from a ZFS pool that runs Docker on which I had Home Assistant. On a whim I decided to delete the old app password, something I had done 7 times previously trying to get this integration to work. Yes, I add numbers to the names of the app passwords when I re-make them to keep track of things like that.

And this time using the docker image method I was able to get a master token.

Don't ask me why, I'd done all these steps multiple times before, deleting and creating a new app password each time and all that.

Maybe I sacrificed enough chickens while rebuilding the server.

thanks for reporting back, @CoryAlbrecht. and happy to hear it went smoother for you this time around

@Maxver0
Copy link

Maxver0 commented Nov 18, 2024

Hello,

For info, a full reboot did not work. To get my master token I choose the solution to install a docker on my Synology NAS through the Container app based on image https://github.com/Brephlas/dockerfile_breph-ha-google-home_get-token. Very simple to use : I just opened a terminal and entered the command python3 get_tokens.py and voilà !

However, for info my master token from aas_et/ to = is only 223 characters long, not 233 as mentionned above and on other forums. Anyways it works in HA : all my devices are now detected. I don't know how long it will last but thank you very much to all of you, you gave me the courage to try harder. It's been 15 days I was struggling with that f*** master token !

I have managed to get the master password using this solution as well.

Unraid Terminal:
docker run -it --name ha-google-get-token breph/ha-google-home_get-token /bin/bash

python3 get_tokens.py

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

10 participants