Skip to content

Commit

Permalink
Making token caching async-safe (#340)
Browse files Browse the repository at this point in the history
Co-authored-by: Dylan Issa <[email protected]>
  • Loading branch information
Anaphylaxis and Dylan Issa authored Jan 9, 2025
1 parent 2c93646 commit f38a9cd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions custom_components/auth_header/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from homeassistant.components.auth import DOMAIN as AUTH_DOMAIN
from homeassistant.components.auth import indieauth
from homeassistant.components.auth.login_flow import LoginFlowIndexView
from homeassistant.components.http import StaticPathConfig
from homeassistant.components.http.ban import log_invalid_auth
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -66,10 +67,15 @@ async def async_setup(hass: HomeAssistant, config):
)

# Load script to store tokens in local storage, else we'll re-auth on every browser refresh.
hass.http.register_static_path(
"/auth_header/store-token.js",
os.path.join(os.path.dirname(__file__), 'store-token.js'),
)
await hass.http.async_register_static_paths(
[StaticPathConfig(
"/auth_header/store-token.js",
os.path.join(os.path.dirname(__file__), 'store-token.js'),
True
)
]
)

add_extra_js_url(hass, '/auth_header/store-token.js')

# Inject Auth-Header provider.
Expand Down

0 comments on commit f38a9cd

Please sign in to comment.