The proper way to remove a refresh token from the list in the user profile is to actively log out from the device, for which this token was created in the first place. But of course nobody does that and so these refresh tokens become an ever growing list of old & abandoned entries over time, including devices that even may not exist anymore to log out from them the proper way.
Currently there doesn’t seem to be an elegant way in HA to server-side cleanup this list apart from deleting expired entries one by one by clicking on the trashcan icon for every user.
So if you are looking for a faster way to get rid of old entries in this list, you may install jq on your HA server (or copy the HA auth file somewhere else, where you have jq installed, modify it and copy the result back) and use the following one liner:
days=7 authfile=<path-to-ha-config-dir>/.storage/auth tmp=$(tempfile) jq --arg s "$(date -d "-$days days" +"%Y-%m-%dT%H:%M")" 'del( .data.refresh_tokens[] | select(.last_used_at < $s) )' $authfile >$tmp && cp $tmp $authfile && rm $tmp
days
defines the number of days since a refresh token was last used and authfile
is the path to the HA auth
file. In the example above all refresh tokens for all users of your HA instance last used more than 7 days ago will be deleted.
Please note, that I’m not sure, if HA is holding the auth file in RAM and is re-reading or updating it sometimes while running. To make sure these changes come into effect, you should restart HA after deleting the tokens or, to play it safe, delete the tokens only while HA is stopped.
If you have jq installed on your HA server, you may also use this one liner in a cron job or you may define a shell_command for it, thus you can trigger the cleanup from the frontend.
Edit: The one liner above temporarily writes the new auth file to the global temp dir of your HA server. If everything is working, it gets deleted immediately after being copied back. But that may not always be the case and there is of course a risk of this file being left in the temp folder.Thus, if you have security concerns writing this file to a “public” folder on your server, you may set the tmp
variable to a location with proper user access restrictions.