Renault-Zoe-API
Renault-Zoe-API copied to clipboard
refresh_token was replaced by xsrfToken
Just recently, in the login answer, the refresh_token was replaced by a xsrfToken. As a result, refreshing no longer works like it used to. The login token's typical validity was also reduced from many hours to a few minutes.
Apparently, the new xsrfToken must be transmitted along with the renewal request as HTTPHeaderField "X-XSRF-TOKEN". Then it works.
Thanks for the research - there's a bit more to it (at least there is now - one gets the impression that they're tinkering with production code somewhat...)
Now when you hit /login
, the response includes a Set-Cookie
header containing a refreshToken
cookie. When you POST
to /refresh
you'll need to include that refresh token in a Cookie
header, as well as the X-XSRF-TOKEN
header containing the xsrfToken
from the login response body.
I'm sure all this seemed a good idea to someone at the time.
Well, for me and the iOS/swift code that I am currently working on, the renewal is still working without explicit such Cookie-Headers. Not sure why, because when I use curl in command line, I do indeed get a "Missing cookie 'refreshToken' " error... I guess the "URLSession" class in iOS just handles the cookies automatically. When I use curl with "-c cookiejar.txt" for the login and with "-b cookiejar.txt" for the renewal, it also succeeds without further explicit data processing or anything on my side.
I've posted a PullRequest relating to this #17
Yesterday when I refreshed the token I figured out, that the refreshToken from the cookie only works with the token you received with the cookie. If you try to refresh the token you have received from the previous refresh you fail. The reason is, that when you receive a refreshed token they also send a new refreshToken via cookie. As the token has a vlidation time of 15 minutes the refreshToken has a validation time of 24 Hours. So at the very end if you refresh a token you get a new token and a new refreshToken via cookie which you have to use then. The xrsfToken can be reused.
I can't accept #17 because I no longer have the vehicle to test with.
If a couple of you test it and report back that it works, I'll merge it.
Tried it:
Traceback (most recent call last):
File "zoe-console.py", line 32, in
@tobintax I think it's an issue with your "credentials_token.json" file being empty. I have update the PR to check for JSONDecodeError and treat it the same as FileNotFoundError
@epenet With your recently changes, the "credentials_token.json" file is not longer empty. Seems ok.
But now I got another error:
Traceback (most recent call last):
File "zoe-console.py", line 46, in
@tobintax there are two packages: myrenault and zeservices. My fix is only for zeservices (to get battery information). For myrenault (to get total mileage), I cannot run it because I am on Renault-FR and all the URLs are different.
Does it work correctly if you remove MyRenaultEmail and MyRenaultPassword from your credentials file? (Note: they need to be completely removed - not just set to blank)
@epenet that did it! Thank you very much!
🔋 84% 🚗 91 miles 🔌 Unplugged ⚡ Not charging