-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Describe the Feature
Now that the refresh_token is set with a device-ID and can be saved there is a new aspect to take into account.
Multiple applications running in parallel using the same refresh-token file cause application to exit with exception error
I am not sure this is an enhancement or a warning with sharing of user experience. I run into this issue today and maybe save time for others.
Example:
background
With each device login a new unique device-ID is assigned for that login. You can do multiple device logins in parallel. The home-installation information as such can be accessed through different device-ID at the same time.
Situation description with saved refresh-token
Once an application-A has started, the refresh_token is obtained and is stored in a file AND in the application-A. The refresh-token in the application-A is continued to be used during the lifetime of application-A. At each access-token refresh (typical every 10 min) also the refresh token is updated in the file and in the application.
The previous refresh-token is NOT valid anymore. If application-A is stopped and restarted it will obtain the latest refresh-token from the file. All that works fine.
Now assume application-A is running continuous in the background. We also have application-B that we run to the same local PyTado instance. Application-B will use the same refresh-token file and it will obtain the refresh-token from that file to obtain the needed access-token. In doing so it will update the refresh-token file AND use the refresh-token in the application-B. NOW as soon as application-A tries to refresh the access token, the application-A has a refresh token that is NOT valid anymore and will fail with an exception.
If we now try to restart application-A, while application-B is still running, the same issue will happen but now application-B will fail with exception.
This only happens if we save the refresh-token in a file and we use the SAME refresh-token file for another application that is running in parallel.
It works fine in parallel if the refresh-token is NOT used from the file as a new unique device-ID is obtained at every login. But then you have to login every time you start the application.
Why Is This Feature Useful?
Reduce to potential on exceptions happening on (background) processes.
In case you want to have ONE refresh-token file that can be shared amount multiple application. In that case it will reduce the number or login's and people do not need to remember which refresh-token file with which application
Proposed Solution
A application-level workaround is provide a different refresh_token file for each application, that forces a one-time login for a new device-ID and thus it can work in parallel on the same PyTado instance.
Alternatives Considered
enhancement could be
If wanting or needing to use the same refresh-token file across different application, a check should added to determine whether the modification time on the file is the same as when last saved by that application.
If not it should first re-load the refresh token file before performing a refresh.
Checklist
- [X ] I have searched the existing issues and discussions to ensure this is not a duplicate.
- [ X] I have provided a clear and concise description of my feature request.
Thank you for helping to improve PyTado! 🚀