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

Authentication Issues After Home Assistant Restart #278

Closed
mike-koch opened this issue May 6, 2024 · 3 comments
Closed

Authentication Issues After Home Assistant Restart #278

mike-koch opened this issue May 6, 2024 · 3 comments

Comments

@mike-koch
Copy link

After having to restart Home Assistant to use a different HACS package, my Emporia authentication stopped working. After trying a couple of things, I ended up uninstalling/reinstalling the Emporia Vue package, and now attempting to authenticate results in the following:

Traceback (most recent call last):
  File "/config/custom_components/emporia_vue/config_flow.py", line 76, in async_step_user
    info = await validate_input(self.hass, user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/emporia_vue/config_flow.py", line 47, in validate_input
    if not await hub.authenticate(data[CONF_EMAIL], data[CONF_PASSWORD]):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/emporia_vue/config_flow.py", line 37, in authenticate
    result = await loop.run_in_executor(None, self.vue.login, username, password)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyemvue/pyemvue.py", line 355, in login
    self.auth = Auth(
                ^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyemvue/auth.py", line 57, in __init__
    self.cognito.authenticate(password=password)
  File "/usr/local/lib/python3.12/site-packages/pycognito/__init__.py", line 495, in authenticate
    self._set_tokens(tokens)
  File "/usr/local/lib/python3.12/site-packages/pycognito/__init__.py", line 767, in _set_tokens
    self.verify_token(
  File "/usr/local/lib/python3.12/site-packages/pycognito/__init__.py", line 266, in verify_token
    raise TokenVerificationException(
pycognito.exceptions.TokenVerificationException: Your 'access_token' token could not be verified (The token is not yet valid (iat)).

It looks like something may have changed in PyEmVue 0.18.5 regarding iat verification. Has this package been updateed to use PyEmVue 0.18.5 by chance?

@magico13
Copy link
Owner

magico13 commented May 6, 2024

You are running into #260, the quick fix is to run an NTP time sync, generally by doing a full hardware level restart. You are correct that 0.18.5 tries to fix this by catching that specific exception and ignoring it, since there's not an official way to adjust the allowed clock skew in pycognito yet (awaiting resolution of NabuCasa/pycognito#225).

Currently this integration is only using 0.18.4, I wasn't fully confident about updating it yet and my development branch has some other changes that aren't ready to pull in yet. You can edit the manifest file to use 0.18.5 instead if you want to try that, but I recommend trying the restart first and only doing that if you continue to see issues with access token verification.

@DabblerIOT
Copy link
Collaborator

DabblerIOT commented May 6, 2024 via email

@mike-koch
Copy link
Author

Thanks for pointing me in the direction regarding NTP syncing. I did a reboot of the VM that's running HA, and all is good now.

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

3 participants