Home
Softono

Hass Auth Cookie

Open source MIT JavaScript
16
Stars
0
Forks
0
Issues
2
Watchers
1 year
Last Commit

 About Hass Auth Cookie

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

Platforms

Web Self-hosted

Languages

JavaScript

Links

Need Help Installing Hass Auth Cookie?

We provide expert installation service for this software. Our team will install, configure, and secure Hass Auth Cookie on your server. plans start at just $30.

Hass Auth Cookie

View on GitHub

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 hass-auth-cookie.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

[!NOTE] It won't work if you enter Home Assistant directly, without proxying by nginx!

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