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 token: NeedsBrowser #245

Closed
ArnyminerZ opened this issue May 19, 2022 · 33 comments · Fixed by #248
Closed

Could not get master token: NeedsBrowser #245

ArnyminerZ opened this issue May 19, 2022 · 33 comments · Fixed by #248
Labels
bug Something isn't working

Comments

@ArnyminerZ
Copy link
Collaborator

Hello,

I have read the other issues with the same error than mine, but I couldn't resolve it.

I use the Google Home addon of Home Assistant, but the connection is refused.
I've tried to take off the protection methods to my google account too.

Here the log :

2022-05-13 10:58:25 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2022-05-13 10:58:25 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
2022-05-13 10:58:25 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "m*******************", password to "V********", master_token to "" and android_id to
2022-05-13 10:58:25 DEBUG (SyncWorker_15) [glocaltokens.client] There is no stored master_token, logging in using username and password
2022-05-13 10:58:25 DEBUG (SyncWorker_15) [glocaltokens.client] There is no stored android_id, generating a new one
2022-05-13 10:58:25 DEBUG (SyncWorker_15) [glocaltokens.client] Generating android id...
2022-05-13 10:58:25 DEBUG (SyncWorker_15) [glocaltokens.client] Generated android id: 02d89392d5f67400
2022-05-13 10:58:25 ERROR (SyncWorker_15) [glocaltokens.client] [!] Could not get master token.
2022-05-13 10:58:25 DEBUG (SyncWorker_15) [glocaltokens.client] Request response: {'Error': 'NeedsBrowser', 'Url': 'https://accounts.google.com/signin/continue?sarp=1&scc=1&continue=https://accounts.google.com/o/android/IDELETEDTHIS', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'} 2022-05-13 10:58:25 ERROR (MainThread) [custom_components.google_home]

Edit: Of course, no pop-up opens.

@ArnyminerZ
Copy link
Collaborator Author

Test performed with the example code, to check at basis if glocaltokens is still working. However, I'm getting the following error:

Traceback (most recent call last):
  File "get_tokens.py", line 6, in <module>
    from glocaltokens.client import GLocalAuthenticationTokens
  File "/home/arnyminerz/.local/lib/python3.8/site-packages/glocaltokens/client.py", line 24, in <module>
    from .google.internal.home.foyer.v1_pb2 import GetHomeGraphRequest, GetHomeGraphResponse
  File "/home/arnyminerz/.local/lib/python3.8/site-packages/glocaltokens/google/internal/home/foyer/v1_pb2.py", line 6, in <module>
    from google.protobuf import (
ModuleNotFoundError: No module named 'google'

Any ideas @leikoilja 🤔

@casper255
Copy link

It's the same for me

Logger: custom_components.google_home
Source: custom_components/google_home/config_flow.py:99
Integration: google_home (documentation, issues)
First occurred: 21:05:56 (1 occurrences)
Last logged: 21:05:56

Logger: glocaltokens.client
Source: /usr/local/lib/python3.9/site-packages/glocaltokens/client.py:224
First occurred: 21:05:56 (1 occurrences)
Last logged: 21:05:56

[!] Could not get master token.

@bjarnekrottje
Copy link

Same error for me.

UI Setup error:
image

Logs:
image
image

Is there a (temporary) fix for this issue?

@tfrubio
Copy link

tfrubio commented May 26, 2022

Same issue. If context helps, fresh/first install of HA/Google home addon today. Have ensured 2FA, SSL via Nabu Casa, using app password, and unlocked captcha

2022-05-25 20:50:56 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
2022-05-25 20:50:56 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "t******************", password to "v***************", master_token to "" and android_id to 
2022-05-25 20:50:56 DEBUG (SyncWorker_2) [glocaltokens.client] There is no stored master_token, logging in using username and password
2022-05-25 20:50:56 DEBUG (SyncWorker_2) [glocaltokens.client] There is no stored android_id, generating a new one
2022-05-25 20:50:56 DEBUG (SyncWorker_2) [glocaltokens.client] Generating android id...
2022-05-25 20:50:56 DEBUG (SyncWorker_2) [glocaltokens.client] Generated android id: 6ee92259b8d78d3a
2022-05-25 20:50:56 ERROR (SyncWorker_2) [glocaltokens.client] [!] Could not get master token.
2022-05-25 20:50:56 DEBUG (SyncWorker_2) [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?<REDACTED AUTH DATA HERE>', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'}
2022-05-25 20:50:56 ERROR (MainThread) [custom_components.google_home] ```

@zhangtemplar
Copy link

Same issue for me.

@isntw
Copy link

isntw commented May 26, 2022

same issue for me

@srappan
Copy link

srappan commented May 26, 2022

Encountering the same error too.

2022-05-26 20:20:41 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2022-05-26 20:20:41 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
2022-05-26 20:20:41 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "s*****************", password to "f***************", master_token to "" and android_id to 
2022-05-26 20:20:41 DEBUG (SyncWorker_6) [glocaltokens.client] There is no stored master_token, logging in using username and password
2022-05-26 20:20:41 DEBUG (SyncWorker_6) [glocaltokens.client] There is no stored android_id, generating a new one
2022-05-26 20:20:41 DEBUG (SyncWorker_6) [glocaltokens.client] Generating android id...
2022-05-26 20:20:41 DEBUG (SyncWorker_6) [glocaltokens.client] Generated android id: 5eeab5fc8c1833e7
2022-05-26 20:20:41 ERROR (SyncWorker_6) [glocaltokens.client] [!] Could not get master token.
2022-05-26 20:20:41 DEBUG (SyncWorker_6) [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=AKgnsbvE0GM96jrnM1SjcgApksTCPV-CUMiXpK4qi_yfB9HADNxoUL_s988cjiGdnV54Gh7_aWuxEmYKR8z74bL6RYPQCZje5-Zyow-48LgIzsqReG8rndiuHOHjXZ-qy6uK3Ik1_iHj', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'}
2022-05-26 20:20:41 ERROR (MainThread) [custom_components.google_home] 

@kyemacdonald
Copy link

Same as the others - requiring web browser to sign in.

@sudoxnym
Copy link

I believe I am experiencing the same issue. I enabled the logger as instructed in the old issue. I wanted to try to help and tried to login to the url it provided in the log... unfortunately it just says "Please Wait". Hope this helps. Let me know if there is anything I should check or try. I don't have any of the integrations mentioned on the old issue.

Stupid Idea, what if I disable 2FA, login, then re-enable 2FA?


2022-05-26` 20:14:44 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2022-05-26 20:14:44 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
2022-05-26 20:14:44 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "p***********************", password to "h***************", master_token to "" and android_id to 
2022-05-26 20:14:44 DEBUG (SyncWorker_1) [glocaltokens.client] There is no stored master_token, logging in using username and password
2022-05-26 20:14:44 DEBUG (SyncWorker_1) [glocaltokens.client] There is no stored android_id, generating a new one
2022-05-26 20:14:44 DEBUG (SyncWorker_1) [glocaltokens.client] Generating android id...
2022-05-26 20:14:44 DEBUG (SyncWorker_1) [glocaltokens.client] Generated android id: (redacted. not sure if its safe to post)
2022-05-26 20:14:44 ERROR (SyncWorker_1) [glocaltokens.client] [!] Could not get master token.
2022-05-26 20:14:44 DEBUG (SyncWorker_1) [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=AKgnsbu06JAWhr6aDij7t_GrWQE1-SitLChjf5e995mXrG8Dhvh8VsJ6bzgt6zpFCp33R9G3eq1OfGjP_7wOU8QEayYSIcCxJFqozRTJSTmTWha_CRwRj9j7gj85QBJUCbIZNusgBJuX', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'}
2022-05-26 20:14:44 ERROR (MainThread) [custom_components.google_home] 

@sudoxnym
Copy link

Just trying to give ideas.. I haven't used this integration before. So I'm not sure if it was this way before it broke, but my other Google based services require you to put the info into the config and when they are sensed, they either pop up with a code and a link to the confirmation site or a persistent notification with the same thing. If you haven't, try taking a look at the code for auth on the Google Fit hacs repo or the Google Calendar integration (I don't know if you can see source code on built in integrations just wanted to try to help)
They require you to set up the API on the development site. Hoping this leads us in the right direction.

@DirkTas67
Copy link

I'm having also this problem, HA is installed on Truenas Scale as Truecharts app.

@ArnyminerZ
Copy link
Collaborator Author

@Pronown yeah, I believe this is the issue. This was working before, so something has changed on Google's side of authentication. Right now I'm totally out of time, but I will try on a fix for this ASAP.

@sudoxnym
Copy link

Hey, no rush, I just figured I'd offer any info I found. Extremely excited to expose these entities to my system. More sensors means more automations for me to dream up.

I tried forcing the "browser" integration to load the url provided in the logs, to see if that would do it, apparently I can't get browser to run at all, nothing happened when I used their direct example to get to Google. - I'm guessing that's because the host machine is RPi 3B+ and I'm pretty sure unless I launch into the UI for the Debian package I'm running, it doesn't actually have a browser? I could be on the wrong track.

As for something I can think of that may be causing 2FA Issues, I know I'm using Google Authenticator as well as a Bluetooth key. It may be freaked out that I have like 14 steps to log in..

@sudoxnym
Copy link

sudoxnym commented May 28, 2022

@DirkTas67
What is the difference in TrueNAS and Home Assistant? From what I just researched it's incomplete, but looks exactly like HA? There were a bunch of abbreviations I didn't understand though, so I'm kinda curious what this software does? If I can use it to tie even more stuff together that would be cool.

@DirkTas67
Copy link

@Pronown HomeAssistant is an app on the Truenas scale system, truenas scale is like a complete OS for NAS and has also apps, apps like Homeassistant, ESPHome, NodeRed, Mosquitto, Zigbee2mqtt..... and many many more

@Neolanco
Copy link

So just to make sure, the issue "'Error': 'NeedsBrowser'" is being worked on right now?
I'm asking because I have the same issue ^^'

@leikoilja
Copy link
Owner

Update:
Just as mentioned above - google has changed some stuff around authentication logic that breaks this package.

The work is going on around in the underlying package gpsoauth that we use in glocaltokens:
simon-weber/gpsoauth#37 (comment)

We should spend all attention to fix it in gpsoauth first and once it's merged and deployed - we look how we need to alter glocaltoken to make it work standalone as well as in ha-google-home package :)

@ArnyminerZ
Copy link
Collaborator Author

Just for reference, the issue has been adressed at simon-weber/gpsoauth#42, now we only have to wait until a new release is published, @simon-weber says it gonna be quick, so let's hope 🤞🏼

@leikoilja
Copy link
Owner

Update:
Kuddos to @CyberAltra and @simon-weber, the issue has been resolved and released in gpsoauth v1.0.1.
Now we just need to bump up the glocaltokens dependency of gpsoauth, test and release as well 🚀 💥

@DirkTas67
Copy link

Thank you for the update; just installed the new version, restarted Homeassistant, installed the integration and added my gmail and app password and it works! Great!

@hugalafutro
Copy link

@DirkTas67 Hi, did you have the integration uninstalled and then installed 1.9.11 or did you update? I'm trying to find a difference in the process as 1.9.11 still doesn't work for me (and presumably whoever upvoted my post @ #528)

@sudoxnym
Copy link

sudoxnym commented Jun 1, 2022

Yeah, same here. Still a no go. Updated via HACS. Removing and reinstalling now.

@srappan
Copy link

srappan commented Jun 1, 2022

2022-06-01 09:59:32 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2022-06-01 09:59:32 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
2022-06-01 09:59:32 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "s*****************", password to "b***************", master_token to "" and android_id to 
2022-06-01 09:59:32 DEBUG (SyncWorker_5) [glocaltokens.client] There is no stored master_token, logging in using username and password
2022-06-01 09:59:32 DEBUG (SyncWorker_5) [glocaltokens.client] There is no stored android_id, generating a new one
2022-06-01 09:59:32 DEBUG (SyncWorker_5) [glocaltokens.client] Generating android id...
2022-06-01 09:59:32 DEBUG (SyncWorker_5) [glocaltokens.client] Generated android id: 269ef5bf05c1882e
2022-06-01 09:59:32 ERROR (SyncWorker_5) [glocaltokens.client] [!] Could not get master token.
2022-06-01 09:59:32 DEBUG (SyncWorker_5) [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=AKgnsbt5TfW_ByZba1pdiUbwOThU9q-n_n7s5iwCI2ad28Ja2hhxUdWg6zaOnh1dt-8pnZvF7Yi29AuDMG9k-K-iIaXrLcsBRHA3CfmvvQ0mywajR_CXW5WSBeW_uthzpgYqsYvTOIJJ', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'}
2022-06-01 09:59:32 ERROR (MainThread) [custom_components.google_home] 

Same error with 1.9.11

@srappan
Copy link

srappan commented Jun 1, 2022

Thank you for the update; just installed the new version, restarted Homeassistant, installed the integration and added my gmail and app password and it works! Great!

Did you set up the integration on a desktop browser? I wonder if it because it's detecting an android user agent and that's why it's failing

@dineshkathir
Copy link

`Logger: glocaltokens.client
Source: /usr/local/lib/python3.9/site-packages/glocaltokens/client.py:224
First occurred: 14:41:44 (3 occurrences)
Last logged: 14:44:54

[!] Could not get master token.`

Still the same error. Unable to log in.
I updated to the new version 1.9.11 and tried to reinstall the integration also.
I have tried both Desktop web and Android applications.

But still facing the same error.

@DirkTas67
Copy link

@srappan Yes, at the desktop browser

@DirkTas67
Copy link

DirkTas67 commented Jun 1, 2022

@hugalafutro No I just updated the integration

I noticed when adding the integration in settings (not hacs) that it took a while for I could enter my email and app password, it was like it was doing something

I also choose a new ''device' password

@bjarnekrottje
Copy link

bjarnekrottje commented Jun 1, 2022

For me too the same error:

2022-06-01 11:37:38 DEBUG (MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
2022-06-01 11:37:38 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
2022-06-01 11:37:38 DEBUG (MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "b************", password to "b***************", master_token to "" and android_id to
2022-06-01 11:37:38 DEBUG (SyncWorker_0) [glocaltokens.client] There is no stored master_token, logging in using username and password
2022-06-01 11:37:38 DEBUG (SyncWorker_0) [glocaltokens.client] There is no stored android_id, generating a new one
2022-06-01 11:37:38 DEBUG (SyncWorker_0) [glocaltokens.client] Generating android id...
2022-06-01 11:37:38 DEBUG (SyncWorker_0) [glocaltokens.client] Generated android id: 8a18675a7afa6051
2022-06-01 11:37:38 ERROR (SyncWorker_0) [glocaltokens.client] [!] Could not get master token.
2022-06-01 11:37:38 DEBUG (SyncWorker_0) [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=AKgnsbvEqZQYwofgrVil4Um2VtvO9qQcVWo1Njgc8VNvpILtIUuerp_udRNBDI25Owldd56rFtLx9HjT_Ej7GjDLCKE8ggxnfiFq7vWDNff4yIHC1ESnc7WkfI8qddfvxUd-us7XtGV-', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'}
2022-06-01 11:37:38 ERROR (MainThread) [custom_components.google_home]

Tried it both on desktop (Windows 11) and in the mobile app (Android 12).

I also firstly updated the Google Home integration via HACS, didn't work. Then I deleted it completely and reinstalled the integration, but that didn't work either.
I'm using 2FA with an app password.

@sudoxnym
Copy link

sudoxnym commented Jun 1, 2022

Installed with updated with HACS via mobile- No go.
Uninstalled.
Reinstalled manually with file from here via destop - No go

2FA set:
Security Key
Email
Google Authenticator
Tap On Phone

If you try to load the url manually I has you log in, then just spins and says please wait or something like that.

Curious why we aren't authenticating Google Home the same way Calendars and Fit are authenticated, or Google Keep? Most of us already have credentials saved in secrets for these services already. Keep has you do the App Password just like we're doing here, but instead of logging in through Settings, just a couple quick lines in config.

Full disclosure, I know very little about coding, but I think this is their authorization process.
'''
import hashlib import gkeepapiimport homeassistant.helpers.config_validation as cvimport voluptuous as volfrom gkeepapi.node import NodeTypefrom homeassistant.components.sensor import ENTITY_ID_FORMAT, PLATFORM_SCHEMAfrom homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_USERNAMEfrom homeassistant.helpers.entity import async_generate_entity_id, Entity DEFAULT_NAME = 'Google Keep'CONF_TITLES = 'titles'CONF_LABELS = 'labels'CONF_PINNED = 'pinned' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_TITLES, default=[]): cv.ensure_list, vol.Optional(CONF_LABELS, default=[]): cv.ensure_list, vol.Optional(CONF_PINNED, default=False): cv.boolean}) def replace_leading_spaces(s): stripped = s.lstrip() return ' ' * 2 * (len(s) - len(stripped)) + stripped def setup_platform(hass, config, add_entities, discovery_info=None): sensor_name = config.get(CONF_NAME) username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) titles = config.get(CONF_TITLES) labels = config.get(CONF_LABELS) pinned = config.get(CONF_PINNED) keep = gkeepapi.Keep() login_success = keep.login(username, password) if not login_success: raise Exception('Invalid username or password') dev = [] hash_value = hashlib.md5(str((username, str(titles), str(labels), pinned)).encode()).hexdigest()[-10:] uid = '{}_{}'.format(sensor_name, hash_value) entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, uid, hass=hass) dev.append(GoogleKeepSensor(entity_id, sensor_name, username, keep, titles, labels, pinned)) add_entities(dev, True
'''

@leikoilja
Copy link
Owner

Opsies, sorry, gents...
Let's move back to ha-google-home issue thread here, since glocaltokens is fixed and python SDK works just fine. Tested both yesterday and today using provided python get_tokens example and works just fine :)

@sudoxnym
Copy link

sudoxnym commented Jun 7, 2022

Opsies, sorry, gents... Let's move back to ha-google-home issue thread here, since glocaltokens is fixed and python SDK works just fine. Tested both yesterday and today using provided python get_tokens example and works just fine :)

I noticed you replied to this after you got the auth figured out, this was about the auth, we're good, sent this before it was figured out. Thank you for everything!

@KaijuKira86
Copy link

cant log in i have the most current version of everything and its a fresh install of google home integration.

2022-08-13 18:13:12.964 ERROR (SyncWorker_3) [glocaltokens.client] [!] Could not get master token. 2022-08-13 18:13:12.974 ERROR (MainThread) [custom_components.google_home] 2022-08-13 18:13:34.122 ERROR (SyncWorker_4) [glocaltokens.client] [!] Could not get master token. 2022-08-13 18:13:34.126 ERROR (MainThread) [custom_components.google_home] 2022-08-13 18:14:05.850 ERROR (SyncWorker_0) [glocaltokens.client] [!] Could not get master token. 2022-08-13 18:14:05.856 ERROR (MainThread) [custom_components.google_home]

@leikoilja
Copy link
Owner

@KaijuKira86, since this issue got marked solved, please open a new issue and provide more details for us to be able to look into it

@leikoilja leikoilja changed the title Can't connect to Google home addon - Could not get master token Could not get master token: NeedsBrowser Aug 15, 2022
Repository owner locked as resolved and limited conversation to collaborators Aug 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.