core icon indicating copy to clipboard operation
core copied to clipboard

Failed to find token, re-authenticate request

Open donoghdb opened this issue 1 year ago • 11 comments

The problem

Every 24 hrs or so if have to re-authenticate the Husqvarna Automower

2024-06-19 17:29:58.353 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request for husqvarna_automower_xxxxxxxxxxxx failed (invalid_grant): Failed to find token 2024-06-19 17:29:58.354 ERROR (MainThread) [homeassistant.components.husqvarna_automower.coordinator] Authentication failed while fetching husqvarna_automower data: Access token failure: 400, message='Bad Request', url=URL('https://api.authentication.husqvarnagroup.dev/v1/oauth2/token')

What version of Home Assistant Core has the issue?

core-2024.6.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

husqvarna_automower

Link to integration documentation on our website

https://www.home-assistant.io/integrations/husqvarna_automower/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

donoghdb avatar Jun 19 '24 20:06 donoghdb

Hey there @thomas55555, mind taking a look at this issue as it has been labeled with an integration (husqvarna_automower) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of husqvarna_automower can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign husqvarna_automower Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


husqvarna_automower documentation husqvarna_automower source (message by IssueLinks)

home-assistant[bot] avatar Jun 19 '24 20:06 home-assistant[bot]

same problem here

pwtanagit avatar Jun 25 '24 13:06 pwtanagit

Not sure, if I can help there, as the token management is done directly by a helper. Can you add these lines to your logger option in the configuration.yaml:

  • homeassistant.components.husqvarna_automower: debug
  • homeassistant.helpers.config_entry_oauth2_flow: debug
  • aioautomower: debug

Example:

logger:
  default: info
  logs:
    homeassistant.components.husqvarna_automower: debug
    homeassistant.helpers.config_entry_oauth2_flow: debug
    aioautomower: debug

And post the logs around the time the error occurs?

Thomas55555 avatar Jun 25 '24 14:06 Thomas55555

I did the logging:

2024-06-26 14:54:07.361 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request for husqvarna_automower_(###application key###) (invalid_grant): Failed to find token 2024-06-26 14:54:07.362 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/aioautomower/auth.py", line 127, in _async_get_access_token return await self.async_get_access_token() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/husqvarna_automower/api.py", line 29, in async_get_access_token await self._oauth_session.async_ensure_token_valid() File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 531, in async_ensure_token_valid new_token = await self.implementation.async_refresh_token(self.token) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 103, in async_refresh_token new_token = await self._async_refresh_token(token) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 193, in _async_refresh_token new_token = await self._token_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 226, in _token_request resp.raise_for_status() File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1070, in raise_for_status raise ClientResponseError( aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://api.authentication.husqvarnagroup.dev/v1/oauth2/token')

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/husqvarna_automower/coordinator.py", line 82, in client_listen await self.client_listen( File "/usr/src/homeassistant/homeassistant/components/husqvarna_automower/coordinator.py", line 82, in client_listen await self.client_listen( File "/usr/src/homeassistant/homeassistant/components/husqvarna_automower/coordinator.py", line 82, in client_listen await self.client_listen( [Previous line repeated 10 more times] File "/usr/src/homeassistant/homeassistant/components/husqvarna_automower/coordinator.py", line 71, in client_listen await automower_client.auth.websocket_connect() File "/usr/local/lib/python3.12/site-packages/aioautomower/auth.py", line 184, in websocket_connect token = await self._async_get_access_token() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aioautomower/auth.py", line 129, in async_get_access_token raise AuthException(f"Access token failure: {err}") from err aioautomower.exceptions.AuthException: Access token failure: 400, message='Bad Request', url=URL('https://api.authentication.husqvarnagroup.dev/v1/oauth2/token') 2024-06-26 15:01:58.997 ERROR (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request for husqvarna_automower(###application key###) (invalid_grant): Failed to find token 2024-06-26 15:01:58.997 ERROR (MainThread) [homeassistant.components.husqvarna_automower.coordinator] Authentication failed while fetching husqvarna_automower data: Access token failure: 400, message='Bad Request', url=URL('https://api.authentication.husqvarnagroup.dev/v1/oauth2/token') 2024-06-26 15:01:58.998 DEBUG (MainThread) [homeassistant.components.husqvarna_automower.coordinator] Finished fetching husqvarna_automower data in 0.282 seconds (success: False)

pwtanagit avatar Jun 26 '24 16:06 pwtanagit

Screenshot_2024-06-20-18-03-31-64_c3a231c25ed346e59462e84656a70e50.jpg

This is an image I managed to capture, not sure it helps.

donoghdb avatar Jun 29 '24 06:06 donoghdb

@Thomas55555 this issue has stopped for me, anyone else?

donoghdb avatar Jul 10 '24 18:07 donoghdb

I can't confirm, that the problem ist solved. HA is on 2024.7.2

I still get "Husqvarna authentication expired" after exactly 24hours (latest message 12min ago, I again have to re-authenticate)

the small message "Translation Error: The intl string context variab ...." also still pops up right before forwarding to api.authentication.husqvarna.com.

pwtanagit avatar Jul 11 '24 10:07 pwtanagit

I still have this issue on 2024.8.1: "The Husqvarna Automower integration needs to re-authenticate with Husqvarna". This happen every 1-2 days or so...

gaborbozoky avatar Aug 11 '24 21:08 gaborbozoky

I confirm, same problem. I also point out that despite numerous tests, I can no longer configure the map display, even though I follow the instructions to the letter of this link: https://github.com/Thomas55555/husqvarna_automower

Danton73 avatar Sep 02 '24 06:09 Danton73

Same problem https://github.com/home-assistant/core/issues/119997#issuecomment-2282892410

JVD1234 avatar Sep 14 '24 12:09 JVD1234

still unsolved on 2024.10.1 : after 24h I have to re-authenticate almost unusable at this stage, a pity

pwtanagit avatar Oct 11 '24 06:10 pwtanagit

still unsolved on 2024.11.3: every 24h I have to re-authenticate (remove/install is not helping)

pwtanagit avatar Nov 24 '24 07:11 pwtanagit

Try to use HA Husqvarna Automower integration. Almost the same and working well ...

https://www.home-assistant.io/integrations/husqvarna_automower

gaborbozoky avatar Nov 24 '24 10:11 gaborbozoky

Try to use HA Husqvarna Automower integration. Almost the same and working well ...

https://www.home-assistant.io/integrations/husqvarna_automower

This is the one I'm using. I followed the docu several times, even re-installed it. Every day I have to re-authenticate. Am I doing something wrong?

image

pwtanagit avatar Nov 25 '24 08:11 pwtanagit

In my case I had the original auth problem so often with Thomas55555's integration like for you. I've deleted the original integration in HA and at Husqarna' too. Then installed the HA version and do the installation process as described and it's now working well since beginning of summer (ca. for 4-5 months).

gaborbozoky avatar Nov 25 '24 08:11 gaborbozoky

I did the same thing as @gaborbozoky months ago: completely uninstalled the Thomas5555 version, restarted HA before installing the official one, and it worked. I only regret that the Thomas5555 integration also had the map feature, which I really liked, and it's not included in the official version.

Danton73 avatar Nov 25 '24 08:11 Danton73

I did as advised (remove it from HA, restart HA and also remove the app from husq_dev and reconfigure). Countdown ist started ;-) -- looking forward thanks to @gaborbozoky and @Danton73

pwtanagit avatar Nov 25 '24 10:11 pwtanagit

I did as advised (remove it from HA, restart HA and also remove the app from husq_dev and reconfigure). Countdown ist started ;-) -- looking forward thanks to @gaborbozoky and @Danton73

update: after 36hours still working, your hints did the trick. thanks.

pwtanagit avatar Nov 27 '24 07:11 pwtanagit

@home-assistant close

Thomas55555 avatar Nov 27 '24 11:11 Thomas55555