evcc icon indicating copy to clipboard operation
evcc copied to clipboard

Oauth refresh token expiring, no way to reauth

Open aguilaair opened this issue 1 year ago • 20 comments

Describe the bug

I have the Volvo API integration and it had been wokring well until recently.

I am now getting: cannot create vehicle type 'template': cannot create vehicle type 'volvo-connected': cannot get vehicles: Get "https://api.volvocars.com/connected-vehicle/v2/vehicles": oauth2: "invalid_grant" "unknown, invalid, or expired refresh token"

As far as I can tell there is no way to re-autheticate and get a new link. This should be detected and a new link should be printed to the log

Steps to reproduce

  1. Use oAuth to autheticate a vehicle
  2. Wait for the refresh_token to expire

Configuration details

N/A - UI configured

Log details

cannot create vehicle type 'template': cannot create vehicle type 'volvo-connected': cannot get vehicles: Get "https://api.volvocars.com/connected-vehicle/v2/vehicles": oauth2: "invalid_grant" "unknown, invalid, or expired refresh token"

TRACE LOGS:


httpd ] TRACE 2025/06/18 23:08:28 GET /api/config/devices/charger/Commander/status
[httpd ] TRACE 2025/06/18 23:08:31 POST /api/config/test/vehicle
[volvo-connected] TRACE 2025/06/18 23:08:31 POST https://volvoid.eu.volvocars.com/as/token.oauth2
[volvo-connected] TRACE 2025/06/18 23:08:31 grant_type=refresh_token&refresh_token=cQ6zGMH7zh.....QDTz -- {"error_description":"unknown, invalid, or expired refresh token","error":"invalid_grant"}
[db ] TRACE 2025/06/18 23:08:31 DELETE FROM `settings` WHERE `settings`.`key` = "oauth.dc-brhrch9....wp2cv" 1 <nil>
[httpd ] TRACE 2025/06/18 23:08:33 GET /api/system/log

What type of operating system or environment does evcc run on?

Linux

External automation

  • [x] I have made sure that no external automation like HomeAssistant or Node-RED is active or accessing any of the mentioned devices when this issue occurs.

Nightly build

  • [x] I have verified that the issue is reproducible with the latest nightly build

Version

No response

aguilaair avatar Jun 18 '25 21:06 aguilaair

/cc @lehmanju

andig avatar Jun 18 '25 21:06 andig

Just use the old link, it stays the same.

lehmanju avatar Jun 19 '25 05:06 lehmanju

where can I find it?

aguilaair avatar Jun 19 '25 07:06 aguilaair

Restart the instance and it should show up in log

lehmanju avatar Jun 19 '25 09:06 lehmanju

Feel free to close this issue, or leave it open to track notifying the user that their token has expired?

aguilaair avatar Jun 20 '25 16:06 aguilaair

@lehmanju does the RT also refresh and so we already store ist if updated? Or does the clientid expire here?

andig avatar Jun 20 '25 16:06 andig

This is just the normal issue of refresh token expiry after 7 days (a volvo api issue).

The clientId expiry is separate and probably hasn't happened to anybody else yet (because my Volvo App is probably the oldest).

lehmanju avatar Jun 20 '25 16:06 lehmanju

And yes, we automatically refresh RT and update them in the store, just doesnt help woth Volvo's API.

lehmanju avatar Jun 20 '25 16:06 lehmanju

I've reached out to Volvo:

we’ve meanwhile hit a real roadblock: https://github.com/evcc-io/evcc/issues/21920#issuecomment-2992215598 According to user feedback, the refresh token apparently expires (although being refreshed itself) after 7 days. At this stage, a fresh login is apparently required. Could you please check/ confirm if that’s the expected behaviour? We’ve also noticed that we can only connect to localhost but for example not evcc.local or IP adress. Is that intended? For user with Homeassisstant and other setups not running on localhost it would be really helpful if these redirect urls could be allowed.

andig avatar Jun 21 '25 08:06 andig

@lehmanju for token expiry, the UI-based login could make the process easier?

andig avatar Jun 21 '25 08:06 andig

Yes, the process would be easier with UI. However, since I have no experience with designing good UI and my time is currently quite scarce, the work on #21266 is stalled.

If there is somebody who is willing to implement the UI part (Vue), I can add the backend functionality.

lehmanju avatar Jun 21 '25 09:06 lehmanju

I have no experience with designing good U

@lehmanju the UI part is already there. The hamburger menu will list any device (not only vehicles) waiting for authentication. All that's missing is the necessary wiring to the device.

andig avatar Jun 21 '25 10:06 andig

Yes, the hamburger menu is useful for already configured vehicles. But what about adding a new vehicle in an unauthenticated state? Afaik it always tries to enumerate the available vehicles before saving the configuration. This isn't possible without authenticating first.

lehmanju avatar Jun 24 '25 07:06 lehmanju

For time being (and I can think about it) it should be possible to add them to yaml if not ui. After restart, hamburger menu should work for login, wdyt?

andig avatar Jun 24 '25 07:06 andig

I have updated the module Volvo4evcc https://github.com/MartijnvanGeffen13/Volvo4evcc to use the new volvo OAUTH client flow and API V2 ,

I noticed that token lifetime has also drastically dropped from 30 min to 5 min, and they added PKCE required now , and HTTP is no longer allowed on callback must be HTTPS (This is now blocking your installation instructions ),

@andig Note that V1 API will be removed in next few months looking at your code you still use the V1 which will be removed soon, you need to update scope you ask from oauth and rewrite for the V2 API aswell.

MartijnvanGeffen13 avatar Jun 25 '25 11:06 MartijnvanGeffen13

and HTTP is no longer allowed on callback must be HTTPS (This is now blocking your installation instructions ),

@MartijnvanGeffen13 also for localhost?

andig avatar Jun 25 '25 17:06 andig

I've already updated the code to match V2 locally, just need to integrate the Hamburger menu ;)

lehmanju avatar Jun 25 '25 18:06 lehmanju

and HTTP is no longer allowed on callback must be HTTPS (This is now blocking your installation instructions ),

@MartijnvanGeffen13 also for localhost?

Correct:, But if you make it https the error disappears and you can create it. so make sure to update that in your docs, and in code if you hardcode it.

And if you want to catch the call back you have to make sure the Cretificate is inplace :) , In my module i now handle this as a manual step so the user copys the browser response to a input field.

Are you also handling PKCE allready as this is now also mandatory

Image

Image

MartijnvanGeffen13 avatar Jun 26 '25 07:06 MartijnvanGeffen13

@lehmanju should this be solved, too?

andig avatar Jun 27 '25 06:06 andig

Yes, this is basically a duplicate of the other Volvo issue anyway.

As for the API and OAuth stuff, that's already adapted for the latest version.

lehmanju avatar Jun 27 '25 11:06 lehmanju