Login Flow creates new Tokens every time
I have successfully configured this plugin using traefik and authelia and it is working nicely.
Unfortunately, it seems that the integration creates a new login token every time I visit my HA instance via the browser, or at least every time a new authelia session is started (although I am using "Remember me" login).
Is this intended? Would it be possible to change the behaviour of the integration so it only generates a new token once, or at least deletes the old token from HA when it is generating a new one?
It seems that the token is not stored on client side, at least on the web fronted (the android app successfully stores the token). I do not understand HAs architecture well enough, but it seems this parameter is somehow missing? https://github.com/home-assistant/frontend/blob/5160a1f55cda94008ca15380b6307b63ca09274b/src/auth/ha-auth-flow.ts#L305
Edit:
Executing
localStorage.setItem("hassTokens", JSON.stringify(window.__tokenCache.tokens))
once stores that token in the local storage.
I think appending storeToken=true to the auth redirect uri will lead to the token being stored by the client. Is this something this integration has control over?
Probably, I haven't really looked into the HASS auth code that this is based on in a while
I "fixed" this by adding a custom lovelace JavaScript-resource which contains the code snippet mentioned above.
I "fixed" this by adding a custom lovelace JavaScript-resource which contains the code snippet mentioned above.
~Could you share and go in a little more detail on how to do this please?~
Edit: Figured it out in the end.. if anyone comes across this same issue:
- Create a new file named
token.jsin thewwwdirectory in the home assistant config directory. - Paste the following contents into
token.js& save:localStorage.setItem("hassTokens", JSON.stringify(window.__tokenCache.tokens)) - Click the "hamburger menu" on your home assistant dashboard -> "Edit dashboard".
- Click the "hamburger menu" on your home assistant dashboard again -> "Manage resources".
- Click "Add resource" button (bottom right of screen).
- Enter
/local/token.jsas URL, "Javascript module" as selection. - Hit "Update".. profit.
Supposedly can be done using the home assistant configuration file, I struggled to find any documentation on how to do this..