Skip to content

Copies Home Assistant access token to a cookie, so you can use an existing authorization result for other subpages or services.

License

Notifications You must be signed in to change notification settings

leshniak/hass-auth-cookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Home Assistant Auth-Cookie

Total downloads

Copies Home Assistant access token to a cookie, so you can use an existing authorization result for other subpages or services.

Useful for zigbee2mqtt, frigate or go2rtc panels in a dockerized setup.

Installation

Follow only one of these installation methods.

Installation and tracking with HACS:
  1. In "Frontend" hit the plus button at the bottom right, search for "Auth Cookie", and install.

  2. Refresh the Dashboard page. You might need to clear the cache.

Manual installation:
  1. Copy swipe-navigation.js from the latest release into /www/hass-auth-cookie/

  2. Add the resource in ui-lovelace.yaml or in Dashboard Resources.

resources:
  # increase this version number at end of URL after each update
  - url: /local/hass-auth-cookie/auth-cookie.js?v=1.0.0
    type: module
  1. Refresh the page, may need to clear cache.

Usage

After an installation, use hass_access_token cookie to get the authorization result from Home Assistant API. For example, in a dockerized setup, you can use a ngx_http_auth_request_module from nginx to perform a subrequest, that will secure another proxied service.

nginx config snippet:

location / {
    proxy_pass http://127.0.0.1:8123/; # Home Assistant instance
    ...
}

location = /_auth {
    internal;
    proxy_pass http://127.0.0.1:8123/api/; # Home Assistant API, required
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_set_header X-Original-URI $request_uri;
    proxy_set_header Authorization "Bearer $cookie_hass_access_token"; # use an access token from the cookie, required
}

location /_sites/zigbee2mqtt/ {
    auth_request /_auth; # perform authorization subrequest, required
    proxy_pass http://127.0.0.1:8080/; # proxied service, eg. zigbee2mqtt frontend
    ...
}

Now create a Home Assistant dashboard with a Webpage card and put /_sites/zigbee2mqtt/ in the URL field. It will load your service in an IFRAME:

HomeAssistant

Star History

Star History Chart

About

Copies Home Assistant access token to a cookie, so you can use an existing authorization result for other subpages or services.

Topics

Resources

License

Stars

Watchers

Forks