Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Unauthorized warning about API key when token is revoked, no way to force login #290

Open
mathieuzimmo opened this issue Dec 22, 2024 · 1 comment

Comments

@mathieuzimmo
Copy link

Describe the bug
My car went to the dealership for a small repair job. I suspect they did something that caused my access tokens to become revoked. The Volvo app returned an error message and I had to log in again. After that, the app was fine.

However, the HA add-on stopped working. I had a hard time getting this fixed because it didn't allow me to force a new login. The only thing I saw in the logs was:

Dec 22 14:59:32 volvo2mqtt [106] - INFO: Starting volvo2mqtt version v1.10.5
Dec 22 14:59:32 volvo2mqtt [106] - DEBUG: MQTT Credentials - Host core-mosquitto Port: 1883 User: addons Pass: <REDACTED>
Dec 22 14:59:32 volvo2mqtt [106] - INFO: Using login from token file
Dec 22 14:59:32 volvo2mqtt [106] - INFO: Refreshing credentials
Dec 22 14:59:32 volvo2mqtt [106] - WARNING: VCCAPIKEY <REDACTED> isn't working! UNAUTHORIZED
Dec 22 14:59:32 volvo2mqtt [106] - DEBUG: [{'key': '<REDACTED>', 'extended': True, 'extended_until': None, 'in_use': False}]
Dec 22 14:59:32 volvo2mqtt [106] - WARNING: No working VCCAPIKEY found, waiting 10 minutes. Then trying again!

The warnings regarding the vcc api key are misleading, in my case the API key was fine. I tried removing and reinstalling the add-on, and I tried recreating the application in my Volvo developer account without success.

Eventually I managed to fix the problem by manually deleting the token file (/usr/share/hassio/addons/local/volvo2mqtt/token/.token). After restarting the add-on I got the 2FA e-mail, updated the OTP code in HA and the connection was successfully restored.

I have a few ideas to improve handling of this type of error:

  • The Volvo api is a bit generic response ("Full authentication is required to access this resource") whenever something is wrong with the api key OR the access token. The given warnings in the add-on shouldn't assume a problem with the api key.
  • Whenever a user changes the VCC Api key, it would make sense to force a login and remove the old token.
  • Would it make sense to create a force login option so the token can be removed manually?

To Reproduce:

Steps to reproduce the behavior:

  1. Setup the integration
  2. Somehow get the token become revoked or invalid
  3. See error
    Entities become stale, after restart they become "unavailable", log mentions warnings regarding the api key

Expected behavior:

Better handle errors caused by the token, allow HA admin to re-login manually or logout

Version info:

INFO: Starting volvo2mqtt version v1.10.5

Logs:

Dec 22 14:59:32 volvo2mqtt [106] - INFO: Starting volvo2mqtt version v1.10.5
Dec 22 14:59:32 volvo2mqtt [106] - DEBUG: MQTT Credentials - Host core-mosquitto Port: 1883 User: addons Pass: <REDACTED>
Dec 22 14:59:32 volvo2mqtt [106] - INFO: Using login from token file
Dec 22 14:59:32 volvo2mqtt [106] - INFO: Refreshing credentials
Dec 22 14:59:32 volvo2mqtt [106] - WARNING: VCCAPIKEY <REDACTED> isn't working! UNAUTHORIZED
Dec 22 14:59:32 volvo2mqtt [106] - DEBUG: [{'key': '<REDACTED>', 'extended': True, 'extended_until': None, 'in_use': False}]
Dec 22 14:59:32 volvo2mqtt [106] - WARNING: No working VCCAPIKEY found, waiting 10 minutes. Then trying again!
@mathieuzimmo mathieuzimmo changed the title WARNING: VCCAPIKEY <REDACTED> isn't working! UNAUTHORIZED Unauthorized warning about API key when token is revoked, no way to force login Dec 22, 2024
@BertilJ
Copy link

BertilJ commented Jan 2, 2025

I'm also sitting with this issue now, a fix for this would be great.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants