TeslaSwift icon indicating copy to clipboard operation
TeslaSwift copied to clipboard

Token expires issue

Open Sniperwolf881 opened this issue 2 years ago • 10 comments

I just recently started using this library, and have faced some issues with the token after logging in.

Same as in the demo, I am storing the api.token.jsonString, and loading the value in AppDelegate by using reuse. When I print it, I get this:

{
  "expires_in" : 28800,
  "refresh_token" : "xxxxxxxx",
  "id_token" : "xxxxxxxx",
  "token_type" : "Bearer",
  "access_token" : "xxxxxxxx",
  "created_at" : 1664609888.676774
}

I changed to xxxxxxxx so the code get's smaller. But, in the expires_in it says 28800. If that is in seconds, that is equals to 8 hours. In my app I get logged out a few times a day. May that be the reason? And what can I do to stay logged in?

Sniperwolf881 avatar Oct 01 '22 07:10 Sniperwolf881

@jonasman Do you have a solution for this, sir? :-)

Sniperwolf881 avatar Oct 02 '22 15:10 Sniperwolf881

I think I have the same issue. I've even setup background tasks to run in my app hoping that it would keep logging in, but it's only running background once a day. It logged out over the course of 2 days.

akac avatar Jan 05 '23 01:01 akac

Is this still valid?

There were some updates to the token code recently

jonasman avatar Apr 30 '23 21:04 jonasman

if not maybe we need to implement some token refresh

jonasman avatar Apr 30 '23 21:04 jonasman

When you say updates to the token code recently - can you point them out? I don't see any new releases to this library to see what that could be.

akac avatar Apr 30 '23 21:04 akac

@akac https://github.com/jonasman/TeslaSwift/commit/f3da37fb7721ba05924b9a956f155219ab1bd274

jonasman avatar Apr 30 '23 21:04 jonasman

I'll have to test that and see.

akac avatar Apr 30 '23 21:04 akac

if something is not working and you want to debug it, refreshWebToken is the function that should refresh the web token

jonasman avatar May 14 '23 11:05 jonasman

@akac and @Sniperwolf881 any news?

jonasman avatar Mar 08 '24 00:03 jonasman

i looked into this, tesla seems to send a validity of 8h for the token, but from my testing the token is not valid this long, probably only 5mins. One way to fix is to force a 5mins token validity instead of using whatever Tesla sends

jonasman avatar Apr 05 '24 21:04 jonasman