hass-auth-header icon indicating copy to clipboard operation
hass-auth-header copied to clipboard

Login Flow creates new Tokens every time

Open jhbruhn opened this issue 3 years ago • 4 comments

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?

jhbruhn avatar Jun 15 '22 20:06 jhbruhn

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?

jhbruhn avatar Jun 15 '22 20:06 jhbruhn

Probably, I haven't really looked into the HASS auth code that this is based on in a while

BeryJu avatar Jun 15 '22 21:06 BeryJu

I "fixed" this by adding a custom lovelace JavaScript-resource which contains the code snippet mentioned above.

jhbruhn avatar Jul 11 '22 22:07 jhbruhn

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:

  1. Create a new file named token.js in the www directory in the home assistant config directory.
  2. Paste the following contents into token.js & save: localStorage.setItem("hassTokens", JSON.stringify(window.__tokenCache.tokens))
  3. Click the "hamburger menu" on your home assistant dashboard -> "Edit dashboard".
  4. Click the "hamburger menu" on your home assistant dashboard again -> "Manage resources".
  5. Click "Add resource" button (bottom right of screen).
  6. Enter /local/token.js as URL, "Javascript module" as selection.
  7. Hit "Update".. profit.

Supposedly can be done using the home assistant configuration file, I struggled to find any documentation on how to do this..

fOmey avatar Aug 27 '22 03:08 fOmey