bpicode / fritzctl

A lightweight, easy to use console client for the AVM FRITZ!Box Home Automation.
MIT License
100 stars 21 forks source link

Manage Fritzbox session expiry #176

Open zakx opened 5 years ago

zakx commented 5 years ago

I've been trying to use a project built on your library that exposes Fritz!DECT smart home devices via HomeKit. In order for that to work, their application needs to run continuously, so it can answer to HomeKit API requests. They will do the Fritzbox login on application start, and everything works well then. After a few minutes (I didn't measure it, I guess about 30 minutes) On/Off requests via HomeKit will stop working. When I call Login() before On(), it will work indefinitely. Therefore I assume that the Fritzbox I am using has some kind of session expiry and I would love if your library would just transparently handle this, for example by checking if the current session would be expired and then logging in again before handling the original API request.

I assume it makes way more sense to fix this here than in the homekit-fritz project. I don't think I can contribute any code though, as I've never done any Go and my frist tries probably shouldn't end up in a decent library. I would appreciate it very much if somebody would consider implementing this. Thanks!

bpicode commented 5 years ago

Hi @zakx,

thx for bringing this up.

Therefore I assume that the Fritzbox I am using has some kind of session expiry

That is correct. Sessions can expire after some time of inactivity. According to the docs it remains valid for 60 minutes after its last use. I have seen boxes behave differently in practice though.

if your library would just transparently handle this, for example by checking if the current session would be expired and then logging in again before handling the original API request.

That sounds like reasonable proposal. The main problem here is that currently there is no bullet-proof way to tell if a session is expired (from a client's perspective). Neither the API by AVM tells when a session loses validity nor do most FBoxes return an interpretable status code (like 401) when trying to use an invalid session.

I assume it makes way more sense to fix this here than in the homekit-fritz project.

I agree that it could be fixed here, provided one can come up with a reliable solution to detect session expiry.

As a side note, it is not uncommon for users of the api to work around this problem, see e.g. jayme-github/fritzbox_smarthome_exporter.

Anyway, I will give this some more thought.

Greets

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.