# `H.Auth`
[🔗](https://github.com/parlant/harness/blob/v0.3.0/lib/h/auth.ex#L1)

Owner bearer token and browser session cookie manager backed by a `:protected`
ETS table and `<data_dir>/auth.token` (`0600`).

Provides constant-time token/cookie verification via `Plug.Crypto.secure_compare/2`
and strict `Host` / `Origin` checks against DNS rebinding and CSRF.

# `allowed_host?`

```elixir
@spec allowed_host?(term(), pos_integer(), keyword()) :: boolean()
```

Validates the HTTP `Host` header against the listener's literal `:bind_address`
(defaults to loopback literals when omitted). Pass `allow_localhost: true`
to also accept `localhost:<port>`.

# `allowed_origin?`

```elixir
@spec allowed_origin?(term(), pos_integer(), keyword()) :: boolean()
```

Validates the HTTP `Origin` as an HTTP URL using the same host policy as `allowed_host?/3`.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `create_browser_session`

```elixir
@spec create_browser_session(term(), GenServer.server(), atom()) ::
  {:ok, String.t()} | {:error, :unauthorized}
```

Verifies `owner_token_candidate` in constant time and, if valid, mints a fresh
32-byte browser session cookie stored in ETS.

# `owner_token`

```elixir
@spec owner_token(atom()) :: String.t()
```

Returns the current owner token from ETS.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the auth manager.

Options:
  * `:data_dir` (required) - root storage directory holding `auth.token`
  * `:name` - GenServer registration name (default `H.Auth`, pass `nil` for unnamed)
  * `:table` - ETS table name (default `:h_auth`)

# `verify_bearer`

```elixir
@spec verify_bearer(term(), atom()) :: boolean()
```

Constant-time comparison of `candidate` against the stored owner token.

# `verify_cookie`

```elixir
@spec verify_cookie(term(), atom()) :: boolean()
```

Constant-time comparison of `cookie_candidate` against active browser session cookies.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
