Git Product home page Git Product logo

glocaltokens's People

Contributors

arnyminerz avatar dependabot[bot] avatar durgnomis-drol avatar kapji avatar leikoilja avatar rounndel avatar samapriya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glocaltokens's Issues

Can't get client.get_google_devices_json to work with master_token instead of password

Describe the bug
Using a client without password doesn't seem to work even though I've previously retrieved a master token and supplied it to the client. I'm getting an error that it can't find the master token, still, and it's still looking for the username and password.

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 "f*******", password to "", master_token to "a******************************************************************************************************************************************************************************************************************************" and android_id to
DEBUG:glocaltokens.client:Initializing models list if empty...
DEBUG:glocaltokens.client:Getting homegraph...
DEBUG:glocaltokens.client:There is no stored homegraph, or it has expired, getting a new one...
DEBUG:glocaltokens.client:There is no access_token stored, or it has expired, getting a new one...
ERROR:glocaltokens.client:Username and password are not set.
DEBUG:glocaltokens.client:Unable to obtain master token.
DEBUG:glocaltokens.client:[GRPC] Unable to obtain access token.
DEBUG:glocaltokens.client:Failed to fetch homegraph

To Reproduce
Running the get token script with user and pass first, obtaining the master token, then commenting out the password and adding the master_token variable.

client = GLocalAuthenticationTokens(
username="username",
master_token="aas_et/mastertokenhere",
#password="realpasshere",
verbose=True,
)

Expected behavior
I'm hoping to use the master token in place of the password and delete it from the folder. Apologies if this is user error!

App Password Errors

I am trying to retrieve the master token as found in your examples. I have put the part before "@gmail.com" in for the username and an app password for my password (I have 2FA on). I get the following error:

ERROR:glocaltokens.client:[!] Could not get master token.
[*] Master token None

I have tried numerous other token retrieval methods including the gist found here: https://rithvikvibhu.github.io/GHLocalApi. Is there some setting I need to update in my google account? I have tried using your ha-google-home library and that seems to not work either as a device does not show up. I have tried it multiple times with the same app password, could this be the issue? Any help would be appreciated. Thanks!

Google: "Error" "BadAuthentication" -- apparently different problem than before?

Describe the bug
I am running a HAOS system in a VM on a NAS. When I try to use the HACS Google-Home integration, it won't accept my username + apppassword. I have 2FA turned on and tried several apppasswords, as well as the username both with and without the @gmail.com.

To Reproduce
Download and setup the Google-Home repository in HACS.
Go to add a new integration.
Enter my full gmail address for the username.
Paste in an app password from Google.
Hit "Submit".
A split second later, I get the message:

Username/Password is incorrect. If your google account has 2FA enabled please generate app password (https://myaccount.google.com/apppasswords). If authentication still fails refer to https://github.com/leikoilja/ha-google-home#troubleshooting

Expected behavior
The service would connect to Google and then discover the Google Home devices I have on my network.

Screenshots
image

Additional context

(MainThread) [glocaltokens.client] Initializing new GLocalAuthenticationTokens instance.
(MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client access_token, homegraph, access_token_date and homegraph_date to None
(MainThread) [glocaltokens.client] Set GLocalAuthenticationTokens client username to "f *******************", password to "z **************", master_token to "" and android_id to
(SyncWorker_9) [glocaltokens.client] There is no stored master_token, logging in using username and password
(SyncWorker_9) [glocaltokens.client] There is no stored android_id, generating a new one
(SyncWorker_9) [glocaltokens.client] Generating android id ...
(SyncWorker_9) [glocaltokens.client] Generated android id: bed9ed3a0e0bc155
(SyncWorker_9) [glocaltokens.client] [!] Could not get master token.
(SyncWorker_9) [glocaltokens.client] Request response: {'Error': 'BadAuthentication')
(MainThread) [custom_components. google home]


Unable to install v0.2.4 on Windows but v0.2.3 works

Windows 10 Installation issue
While I am able to install and use glocaltokens==0.2.3 on my machine v 0.2.4 is giving me the following error.

Setup details:
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32

    ERROR: Command errored out with exit status 1:
     command: 'c:\pythonenv\venv3\scripts\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\samapriya\\AppData\\Local\\Temp\\pip-install-e9v3zubr\\glocaltokens\\setup.py'"'"'; __file__='"'"'C:\\Users\\samapriya\\AppData\\Local\\Temp\\pip-install-e9v3zubr\\glocaltokens\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: C:\Users\samapriya\AppData\Local\Temp\pip-install-e9v3zubr\glocaltokens\
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\samapriya\AppData\Local\Temp\pip-install-e9v3zubr\glocaltokens\setup.py", line 7, in <module>
        HISTORY = history_file.read()
      File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 107: character maps to <undefined>
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I was able to install pycryptodomex based on instructions on their page and I am running v0.2.3 in the meantime.

Add tests for device json fetching

Describe the bug
Would be great to add a Client test for that one. This method must be quite robust, so it's important we have it covered with tests.

Expected behavior
Nice and clean tests to ensure we have got that functionality covered

Blocked by #22

Device unique id parameter

Let's find a way to extract a unique ID from homegraph or eureka endpoint to pass it for each of devices

Can't install on Home Assistant Container 2021.8.8

Describe the bug
Can't install ha-googlehome due to glocaltokens issue.

To Reproduce
Steps to reproduce the behavior:

  1. Install HA Container 2021.8.8
  2. Install gcc and c++ container through apk add
  3. Install grpcio-tools manually
  4. Install glocaltokens manually

Expected behavior
glocaltokens to install properly

Additional context
Seems like the libraries that HA has already installed are newer than glocaltokens uses:

Logs from installing glocaltokens manually:

bash-5.1# pip install glocaltokens
Requirement already satisfied: glocaltokens in /usr/local/lib/python3.9/site-packages (0.4.0)
Collecting zeroconf<0.30.0,>=0.28.8
  Using cached zeroconf-0.29.0-py3-none-any.whl (55 kB)
Requirement already satisfied: requests<3.0.0,>=2.25.1 in /usr/local/lib/python3.9/site-packages (from glocaltokens) (2.25.1)
Requirement already satisfied: gpsoauth<2.0.0,>=1.0.0 in /usr/local/lib/python3.9/site-packages (from glocaltokens) (1.0.0)
Requirement already satisfied: grpcio==1.31.0 in /usr/local/lib/python3.9/site-packages (from glocaltokens) (1.31.0)
Requirement already satisfied: simplejson<4.0.0,>=3.17.2 in /usr/local/lib/python3.9/site-packages (from glocaltokens) (3.17.3)
Requirement already satisfied: grpcio-tools==1.31.0 in /usr/local/lib/python3.9/site-packages (from glocaltokens) (1.31.0)
Requirement already satisfied: six>=1.5.2 in /usr/local/lib/python3.9/site-packages (from grpcio==1.31.0->glocaltokens) (1.16.0)
Requirement already satisfied: protobuf<4.0dev,>=3.5.0.post1 in /usr/local/lib/python3.9/site-packages (from grpcio-tools==1.31.0->glocaltokens) (3.17.3)
Requirement already satisfied: pycryptodomex>=3.0 in /usr/local/lib/python3.9/site-packages (from gpsoauth<2.0.0,>=1.0.0->glocaltokens) (3.10.1)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.9/site-packages (from requests<3.0.0,>=2.25.1->glocaltokens) (2.10)
Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.9/site-packages (from requests<3.0.0,>=2.25.1->glocaltokens) (4.0.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/site-packages (from requests<3.0.0,>=2.25.1->glocaltokens) (1.26.6)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from requests<3.0.0,>=2.25.1->glocaltokens) (2021.5.30)
Requirement already satisfied: ifaddr>=0.1.7 in /usr/local/lib/python3.9/site-packages (from zeroconf<0.30.0,>=0.28.8->glocaltokens) (0.1.7)
Installing collected packages: zeroconf
  Attempting uninstall: zeroconf
    Found existing installation: zeroconf 0.35.0
    Uninstalling zeroconf-0.35.0:
      Successfully uninstalled zeroconf-0.35.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
python-miio 0.5.6 requires click<8,>=7, but you have click 8.0.1 which is incompatible.
python-miio 0.5.6 requires defusedxml<0.7,>=0.6, but you have defusedxml 0.7.1 which is incompatible.
netdisco 2.9.0 requires zeroconf>=0.30.0, but you have zeroconf 0.29.0 which is incompatible.
hap-python 3.6.0 requires zeroconf>=0.32.0, but you have zeroconf 0.29.0 which is incompatible.
aiohomekit 0.6.0 requires zeroconf>=0.32.0, but you have zeroconf 0.29.0 which is incompatible.
aioesphomeapi 6.0.1 requires zeroconf<1.0,>=0.32.0, but you have zeroconf 0.29.0 which is incompatible.
Successfully installed zeroconf-0.29.0

Logs from ha-googlehome:

2021-08-27 15:21:52 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package glocaltokens==0.3.1: ERROR: Cannot install glocaltokens==0.3.1 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
2021-08-27 15:21:52 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 89, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 128, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 63, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 72, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 153, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 171, in _async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 693, in async_create_flow
    await async_process_deps_reqs(self.hass, self._hass_config, integration)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 375, in async_process_deps_reqs
    await requirements.async_get_integration_with_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 84, in async_get_integration_with_requirements
    await _async_process_integration(hass, integration, done)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 100, in _async_process_integration
    await async_process_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 164, in async_process_requirements
    raise RequirementsNotFound(name, [req])
homeassistant.requirements.RequirementsNotFound: Requirements for google_home not found: ['glocaltokens==0.3.1'].

Add typing

Is your feature request related to a problem? Please describe.
Modern IDEs use typing to make small errors like typos, or bad types mixing easier with typing. This should be implemented to have a cleaner code, since the variable types would be known.

Describe the solution you'd like
Add typing to all the expressions in the library, for example:

def __init__(self, username:str = None, password:str = None):

Google Nest Mini no IP or Port found

Describe the bug

Does not find an IP or Port for Google Nest Mini

(Igonere my TV)
2021-02-16 17:07:36 DEBUG (SyncWorker_1) [custom_components.ha-glocaltokens] [{'device_name': 'Simons TV', 'local_auth_token': 'devicetoken', 'google_device': {'ip': None, 'port': None}}, {'device_name': 'Køkken', 'local_auth_token': device-token', 'google_device': {'ip': None, 'port': None}}]

Expected behavior
IP and Port not None

Implement access token error handling

Is your feature request related to a problem? Please describe.
The access token is changed every ~1h. It is currently stored locally. So if the client hangs for a few hours locally storred access token will not be valid anymore

Describe the solution you'd like
Implement error handling when the access token is incorrect to retry by the first refreshing access token using master token.

Closed in #9

Cannot get master token, requires browser

Describe the bug
Trying to use the example script to acquire a master token. I've logged in using an app password and the script outputs an error

To Reproduce
Steps to reproduce the behavior:

  1. Generate app password
  2. Run script with app password
  3. spits out error
    I am on a Macbook pro and my google account uses a passkey to sign in

Expected behavior
Output of master token

Additional context
Error logs:

ERROR:glocaltokens.client:[!] Could not get master token.
DEBUG:glocaltokens.client:Request response: {'Error': 'NeedsBrowser', 'Url': '[redacted]', 'ErrorDetail': 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.'}
DEBUG:glocaltokens.client:Unable to obtain master token.
DEBUG:glocaltokens.client:[GRPC] Unable to obtain access token.
DEBUG:glocaltokens.client:Failed to fetch homegraph
[*] Google devices "[]"

Error with installing package glocaltokens==0.6.2 after upgrade to HA 2022.3.0b0

Describe the bug
After upgrade HA to 2022.3.0b0 in logs I see error with installing package glocaltokens connected to pypa/pip#10825

2022-02-24 07:42:45 ERROR (SyncWorker_6) [homeassistant.util.package] Unable to install package glocaltokens==0.6.2: warning: missing-index-doctype

× The package index page being used does not have a proper HTML doctype declaration.
╰─> Problematic URL: https://wheels.home-assistant.io/alpine-3.14/amd64/

note: This is an issue with the page at the URL mentioned above.
hint: You might need to reach out to the owner of that package index, to get this fixed. See pypa/pip#10825 for context.
ERROR: Cannot install glocaltokens==0.6.2 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

homeassistant.requirements.RequirementsNotFound: Requirements for google_home not found: ['glocaltokens==0.6.2'].

From Home Assistant side there is general issue home-assistant/home-assistant.io#21766

To Reproduce
Steps to reproduce the behavior:
Upgrade Home Assistant from 2022.2.9 to 2022.3.0b0

Expected behavior
Packages are installed as in previous version

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Error when running sample: ModuleNotFoundError: No module named 'google'

Describe the bug
I've followed the instructions in the README but when running it I receive the following error:

raceback (most recent call last):
  File "/workspaces/tmp-ha-google/get-token.py", line 1, in <module>
    from glocaltokens.client import GLocalAuthenticationTokens
  File "/home/vscode/.local/lib/python3.10/site-packages/glocaltokens/client.py", line 24, in <module>
    from .google.internal.home.foyer.v1_pb2 import GetHomeGraphRequest, GetHomeGraphResponse
  File "/home/vscode/.local/lib/python3.10/site-packages/glocaltokens/google/internal/home/foyer/v1_pb2.py", line 6, in <module>
    from google.protobuf import (
ModuleNotFoundError: No module named 'google'

This is in an isolated environment with python 3.10.4 installed (I ran a fresh Docker image with only Python 3 in it).

Full terminal logs:

vscode ➜ /workspaces/tmp-ha-google $ pip install glocaltokens
Defaulting to user installation because normal site-packages is not writeable
Collecting glocaltokens
  Downloading glocaltokens-0.6.4-py3-none-any.whl (37 kB)
Collecting grpcio<2.0.0,>=1.44.0
  Downloading grpcio-1.47.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 8.5 MB/s eta 0:00:00
Collecting zeroconf<0.39.0,>=0.38.3
  Downloading zeroconf-0.38.7-py3-none-any.whl (106 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 106.6/106.6 KB 7.8 MB/s eta 0:00:00
Collecting requests<3.0.0,>=2.27.1
  Downloading requests-2.28.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.8/62.8 KB 4.2 MB/s eta 0:00:00
Collecting simplejson<4.0.0,>=3.17.2
  Downloading simplejson-3.17.6-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (137 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 137.1/137.1 KB 8.4 MB/s eta 0:00:00
Collecting gpsoauth<2.0.0,>=1.0.1
  Downloading gpsoauth-1.0.2-py3-none-any.whl (6.6 kB)
Collecting pycryptodomex>=3.0
  Downloading pycryptodomex-3.15.0-cp35-abi3-manylinux2010_x86_64.whl (2.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 6.9 MB/s eta 0:00:00
Collecting six>=1.5.2
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 139.0/139.0 KB 8.8 MB/s eta 0:00:00
Collecting charset-normalizer~=2.0.0
  Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
  Downloading certifi-2022.6.15-py3-none-any.whl (160 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 160.2/160.2 KB 9.8 MB/s eta 0:00:00
Collecting idna<4,>=2.5
  Downloading idna-3.3-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 KB 5.2 MB/s eta 0:00:00
Collecting ifaddr>=0.1.7
  Downloading ifaddr-0.2.0-py3-none-any.whl (12 kB)
Installing collected packages: ifaddr, zeroconf, urllib3, six, simplejson, pycryptodomex, idna, charset-normalizer, certifi, requests, grpcio, gpsoauth, glocaltokens
Successfully installed certifi-2022.6.15 charset-normalizer-2.0.12 glocaltokens-0.6.4 gpsoauth-1.0.2 grpcio-1.47.0 idna-3.3 ifaddr-0.2.0 pycryptodomex-3.15.0 requests-2.28.0 simplejson-3.17.6 six-1.16.0 urllib3-1.26.9 zeroconf-0.38.7
WARNING: You are using pip version 22.0.4; however, version 22.1.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
vscode ➜ /workspaces/tmp-ha-google $ python3 get-token.py 
Traceback (most recent call last):
  File "/workspaces/tmp-ha-google/get-token.py", line 1, in <module>
    from glocaltokens.client import GLocalAuthenticationTokens
  File "/home/vscode/.local/lib/python3.10/site-packages/glocaltokens/client.py", line 24, in <module>
    from .google.internal.home.foyer.v1_pb2 import GetHomeGraphRequest, GetHomeGraphResponse
  File "/home/vscode/.local/lib/python3.10/site-packages/glocaltokens/google/internal/home/foyer/v1_pb2.py", line 6, in <module>
    from google.protobuf import (
ModuleNotFoundError: No module named 'google'
vscode ➜ /workspaces/tmp-ha-google $ 

Add debugging

Describe the solution you'd like
Add more debugging through logging so bug searching is easier.

Could not get master token: NeedsBrowser

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.

Support authentication with only master token

Is your feature request related to a problem? Please describe.
We should be able to support master token authentication alone for those clients that are not willing to provide their google user and password credentials. See here - leikoilja/ha-google-home#124 (comment)

Describe the solution you'd like
Feeding just master_token to the client should be sufficient for the client's work

Additional context
I think we already mostly support this except that we have some extra protective logic that will return None and log an error if no login or no password are provided (See

)

Requirements:

  • We need to test the functionality works as expected
  • We need to make sure we cover the implementation with sufficient unit tests

Error in retrieving local authorization token

Hi leikoilja -

first of all - thanks a lot for putting this together!

I'm able to retrieve Master and Access token.
Unfortunately I have struggled with retrieving the local authorization key.

Do you understand the error below?
If so how can I fix?

Really appreciate your help!

Best,
Sandro

[*] Google devices local authentication tokens
Traceback (most recent call last):
  File "/Users/sandro-berchier/Documents/SmartHome/test.py", line 17, in <module>
    google_devices = client.get_google_devices_json()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/glocaltokens/client.py", line 126, in get_google_devices_json
    homegraph = self.get_homegraph()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/glocaltokens/client.py", line 117, in get_homegraph
    response = rpc_service.GetHomeGraph(request)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grpc/_channel.py", line 923, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/grpc/_channel.py", line 826, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.INTERNAL
        details = "Exception deserializing response!"
        debug_error_string = "None"
>

get_android_id method fails of arm

Describe the bug
The method which generates random android id relies on from uuid import getnode that is underlying the hardware address. On amd devices this method return 14 digits number, while on arm 15 digits long number.

Expected behavior
We don't really need to rely on getnode, we should be able just to randomly generate a consistent length string as an android id

Warning when not using HA-zeroconf

Describe the bug

2021-02-16 16:54:24 WARNING (SyncWorker_1) [homeassistant.helpers.frame] Detected integration that attempted to create another Zeroconf instance. Please use the shared Zeroconf via await homeassistant.components.zeroconf.async_get_instance(hass). Please report issue to the custom component author for ha-glocaltokens using this method at custom_components/ha-glocaltokens/api.py, line 74: devices = json.loads(self._client.get_google_devices_json())

Package wheels fails to build because of grpcio, grpcio-tools missing system packages/compilers

Describe the bug
Package fails to build because it relies on wheels for grpcio, grpcio-tools.

Expected behavior
It would be nice to find a solution in-line with current Home Assistant version, so the package would work with HA on arm devices too. Preferably without installing any additional system packages/compilers, since not every user will have access/knowledge to do so.

Reference from #6 (comment):

But i ran into this problem with the docker version of homeassistant, because it runs on an alpine image, grpcio and grpcio-tools dosent install corretly if you dont install them manually in the docker image, and add "apk add gcc g++ linux-headers".

Do not initialise Devices with invalid `local_auth_token`

Describe the bug
When we get a fresh homegraph we iterate through devices creating new instances Device ref for each of discovered devices. In the Device initialization __init__ we do the validation for local_auth_token, however, if the validation fails we still return the "half-baked" object back to devices that is later used.

** Referece **
See the issue here

To Reproduce
Put a debugger breakpoint right before token validation and temper with a token.

Expected behavior
If any of the validations fail - skip adding the device

[aiohttp.server] Error handling request

Fantastic work guys!

I have tried installing the latest version and it went fine on hacs until i tried to enter my app password.

Since i'm using 2fa, i need to use the app password. When entering and saving, the following error is displayed.

Any suggestions on what i can do to fix?

2021-03-02 11:37:48 WARNING (MainThread) [homeassistant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for glocaltokens doing I/O at custom_components/glocaltokens/api.py, line 36: master_token = self._client.get_master_token()
2021-03-02 11:37:48 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 169, in post
return await super().post(request, flow_id)
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
result = await method(view, request, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 106, in post
result = await self._flow_mgr.async_configure(flow_id, data)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 155, in async_configure
result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 213, in _async_handle_step
result: Dict = await getattr(flow, method)(user_input)
File "/config/custom_components/glocaltokens/config_flow.py", line 46, in async_step_user
CONF_ANDROID_ID: client.get_android_id(),
File "/config/custom_components/glocaltokens/api.py", line 48, in get_android_id
return self._client._get_android_id()
AttributeError: 'GLocalAuthenticationTokens' object has no attribute '_get_android_id'

Can't get token on python 3.10

Hello

Describe the bug
When I use the script on the readme, it work great with python 3.9 but not with 3.10

To Reproduce
Steps to reproduce the behavior:

Install ubuntu 20.04.
Install glocaltokens
Install python3-pip
pip3 install glocaltokens
Use the test script, it work.

Upgrade ubuntu to 22.04 (which come with python 3.10)
Reinstall pip3 install glocaltokens
Retry the same script: "Could not get master token."

I don't know if the problem come from the python version or the dependances, but I first have the problem with a fresh ubuntu 22.04. Then I test on 20.04 without error, so I try with a fresh vm with 20.04 and then upgrading it to confirm the problem

Client's get_google_devices_json method returns list

Describe the bug
Method that is described as json returns a list of devices.
See https://github.com/leikoilja/glocaltokens/blob/master/glocaltokens/client.py

    def get_google_devices_json(self):
        """
        Returns a json of google devices with their
        local authentication tokens
        """

        def extract_devices(items):
            """
            Replacement for jq
            """
            devices = []
            for item in items:
                if item.local_auth_token != "":
                    device = {
                        'deviceName': item.device_name,
                        'localAuthToken': item.local_auth_token,
                    }
                    devices.append(device)
            return devices

        homegraph = self.get_homegraph()

        devices = extract_devices(homegraph.home.devices)

        return devices

Expected behavior
We should either return a json or a list. If former, then we should rename the method and announce a breaking change.

Release 0.2.7

Can you release new version with typing information? I can use it in ha-google-home then.

Authentication error after ~22h of usage

Describe the bug
Left the Google Home HA integration for 24h and after the time has passed I have discovered that integration fails to fetch data due to authentication error.
image

While this should not happen and tokens must be automatically refreshed by glocaltokens library. I am afraid it might not be working... OR we might need to shorten the access token and homegraph durations. @ArnyminerZ, do you have any thoughts?

`Castlistner` should implement `remove_service`

Describe the bug

2021-03-21 10:56:13 ERROR (zeroconf-ServiceBrowser__googlecast._tcp.local._264) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/site-packages/zeroconf/__init__.py", line 1760, in run
    self._service_state_changed.fire(
  File "/usr/local/lib/python3.8/site-packages/zeroconf/__init__.py", line 1513, in fire
    h(**kwargs)
  File "/usr/local/lib/python3.8/site-packages/zeroconf/__init__.py", line 1618, in on_change
    listener.remove_service(*args)
AttributeError: 'CastListener' object has no attribute 'remove_service'

See this link Homeassistant/core#48117

To Reproduce

Appears first time i restart, but only once.

Expected behavior
A clear and concise description of what you expected to happen.

No error message.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Long passwords cause login issues

Describe the bug
When long passwords are used (100+ characters), which are not supported by Google, an issue is thrown. More info in leikoilja/ha-google-home#430

Partial logs:

  File "/usr/local/lib/python3.9/site-packages/glocaltokens/client.py", line 218, in get_master_token
    res = perform_master_login(
  File "/usr/local/lib/python3.9/site-packages/gpsoauth/__init__.py", line 127, in perform_master_login
    "EncryptedPasswd": google.construct_signature(
  File "/usr/local/lib/python3.9/site-packages/gpsoauth/google.py", line 58, in construct_signature
    encrypted_login = cipher.encrypt((email + "\x00" + password).encode("utf-8"))
  File "/usr/local/lib/python3.9/site-packages/Cryptodome/Cipher/PKCS1_OAEP.py", line 115, in encrypt
    raise ValueError("Plaintext is too long.")
ValueError: Plaintext is too long.

Possible solution:
Add a try-catch to /glocaltokens/client.py#L220 which catches the ValueError.

403 when trying to get master token

I'm trying to use the HA integration and came across the auth problem (leikoilja/ha-google-home#528) so it was suggested I just try using the raw package.

When I run it with my credentials I get a 403 from the API calls:

vscode ➜ /workspaces/tmp-ha-google $ python3 get-token.py 
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): android.clients.google.com:443
DEBUG:urllib3.connectionpool:https://android.clients.google.com:443 "POST /auth HTTP/1.1" 403 None
ERROR:glocaltokens.client:[!] Could not get master token.
[*] Master token None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): android.clients.google.com:443
DEBUG:urllib3.connectionpool:https://android.clients.google.com:443 "POST /auth HTTP/1.1" 403 None
ERROR:glocaltokens.client:[!] Could not get master token.

[*] Access token (lives 1 hour) None

[*] Google devices local authentication tokens
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): android.clients.google.com:443
DEBUG:urllib3.connectionpool:https://android.clients.google.com:443 "POST /auth HTTP/1.1" 403 None
ERROR:glocaltokens.client:[!] Could not get master token.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): android.clients.google.com:443
DEBUG:urllib3.connectionpool:https://android.clients.google.com:443 "POST /auth HTTP/1.1" 403 None
ERROR:glocaltokens.client:[!] Could not get master token.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): android.clients.google.com:443
DEBUG:urllib3.connectionpool:https://android.clients.google.com:443 "POST /auth HTTP/1.1" 403 None
ERROR:glocaltokens.client:[!] Could not get master token.

The Python script I'm running is off the README for the repo, with the only change being I've put in my username/password.

I've tried with 2FA enabled and an App Password, and I've tried turning off 2FA and using a username/password, both output the same thing.

Arm and grpcio, grpcio-tools and jq

Describe the bug
I have been trying to make an custom component that generate sensors form timers and alarms, a little different then the custom component you have made. But i ran into this problem with the docker version of homeassistant, because it runs on an alpine image, grpcio and grpcio-tools dosent install corretly if you dont install them manually in the docker image, and add "apk add gcc g++ linux-headers" before doing so. My docker runs on a raspberry pi 4, so i dont know if its only a Arm issue.

Is there anyway we can solve this.

Jq doesnt work either on Arm/Raspberry pi 4
I have not uploaded my component to github yet, but i plan to as soon as you either merge my pull request on jq or find another way to get rid of jq.

To Reproduce

Expected behavior

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

how to disable your master token

Describe the bug
Run the docker to make a master token 3 times. I have got now 3 master tokens. How to remove 2 of master tokens?

Limit device discovery by Homes

Is your feature request related to a problem? Please describe.
When multiple homes exist in the Google Home app, this integration discovers devices from all connected homes.

Describe the solution you'd like
Ability to limit google device discovery to a particular home if desired.

Additional context
Related to leikoilja/ha-google-home#363

Module 'urllib3.util.ssl_' has no attribute 'DEFAULT_CIPHERS' on python 3.10

Describe the bug
trying to get master token .
When running the example on the first page
from glocaltokens.client import GLocalAuthenticationTokens

# Using google username and password first, and only once
client = GLocalAuthenticationTokens(
  username="usrname",
  password="app password"
)

# Get master token
master_token = client.get_master_token()
print("[*] Master token", master_token)

getting error

Traceback (most recent call last):
  File "/config/get_token.py", line 10, in <module>
    master_token = client.get_master_token()
  File "/usr/lib/python3.10/site-packages/glocaltokens/client.py", line 230, in get_master_token
    res = perform_master_login(
  File "/usr/lib/python3.10/site-packages/gpsoauth/__init__.py", line 143, in perform_master_login
    return _perform_auth_request(data, proxy)
  File "/usr/lib/python3.10/site-packages/gpsoauth/__init__.py", line 78, in _perform_auth_request
    session.mount(AUTH_URL, AuthHTTPAdapter())
  File "/usr/lib/python3.10/site-packages/requests/adapters.py", line 155, in __init__
    self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
  File "/usr/lib/python3.10/site-packages/gpsoauth/__init__.py", line 68, in init_poolmanager
    context.set_ciphers(ssl_.DEFAULT_CIPHERS)
AttributeError: module 'urllib3.util.ssl_' has no attribute 'DEFAULT_CIPHERS'

Add more logging

There should be a pretty exhaustive debug log in the library, just in case something fails, it's easier to find where it's broken, and find a solution.

Getting Logged out of my Google Account

Describe the bug
When I use the script, when it's executed I get logged out of the Google Account of my Android phone.

To Reproduce
I have developed an script for Home Assistant that loads the alarms from my Lenovo Smart Clock, and loads them. When I use the script with the following sensor configuration:

  - platform: command_line
    command: /home/homeassistant/clock.sh
    name: alarms
    scan_interval: 30
    json_attributes:
      - alarm
      - timer
    value_template: "{{ value_json.alarm[0] }}"

when it gets executed, my Google Account at my Android Phone gets bugged, and asks me to log in again, blocking the use of any Google App at my device until I log in again.

Expected behavior
I should not get logged out.

Server:

  • OS: Raspbian OS
  • Version: Linux emonpi 5.10.11-v8+ #1399 SMP PREEMPT Thu Jan 28 12:14:03 GMT 2021 aarch64 GNU/Linux
  • Platform: Home Assistant (2021.2.0)
  • Python Version: 3.8.7

Smartphone (please complete the following information):

  • Device: Google Pixel 3a
  • OS: Android
  • Version: 11 (RQ1A.210205.004)

Additional context
I'm using an app password instead of my Google's Account password.

Strange bug with requests version 2.23 larger then

Describe the bug
A bug were gpsoauth does not work with requests versions larger then. If you downgrade to 2.23 and then upgrade again to the newest version. it then works.

See here: gpsoauth

To Reproduce

Expected behavior

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

Add testing environment and unit tests

Is your feature request related to a problem? Please describe.
Now that the package is slowly growing and more people contributing we need to setup testing environment with unit tests.

Describe the solution you'd like
Preferably tox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.