# ha_auth v0.1.0 - API Reference

## Modules

- [HaAuth](HaAuth.md): Sign in to a Phoenix app through Home Assistant, three ways, all on one
login page (`HaAuth.Web.LoginLive`)
- [HaAuth.Access](HaAuth.Access.md): Who may sign in: HA admins always, other HA users when their id is in
`config :ha_auth, :allowed_users`. Checked at sign-in and again on every
request and LiveView mount, so dropping someone locks them out at once.

- [HaAuth.Config](HaAuth.Config.md): Settings, from `config :ha_auth, ...` (usually in `config/runtime.exs`)
- [HaAuth.HA.Events](HaAuth.HA.Events.md): Websocket to HA, subscribed to `call_service`, for Kiosk Satellite
sign-in: a `persistent_notification.dismiss` of an
`ha_auth_sign_in_<nonce>` id goes to `HaAuth.KioskSignIn` with the HA
user HA says made the call. Started only with `kiosk: true` and a token
(admin, since other users' events are admin-only). Reconnects on drops.

- [HaAuth.HA.OAuth](HaAuth.HA.OAuth.md): Home Assistant's OAuth2 (IndieAuth flavour): no client registration, the
app's base URL is the `client_id` and the redirect URI is on the same
host. See https://developers.home-assistant.io/docs/auth_api/
- [HaAuth.HA.OneShot](HaAuth.HA.OneShot.md): One websocket command to HA: connect, authenticate with `token`, send
`command`, return its result, close. For what HA only offers over the
websocket (`auth/current_user`, `config/auth/list`).

- [HaAuth.HA.Users](HaAuth.HA.Users.md): HA's people (`config/auth/list`, admin-only and websocket-only, so it
needs an admin `:token`). Used to name the user a kiosk signs in as.
Swap in a stub with `config :ha_auth, :users_source, Mod`.

- [HaAuth.KioskSignIn](HaAuth.KioskSignIn.md): Sign-in without a button on Kiosk Satellite tablets.
- [HaAuth.LiveAuth](HaAuth.LiveAuth.md): `on_mount` for LiveViews: `live_session :app, on_mount: {HaAuth.LiveAuth,
:require_user}` assigns `:current_user` or sends the browser to `/login`.

- [HaAuth.Pairings](HaAuth.Pairings.md): QR sign-in. The login page holds a code (in its session) and shows
`/pair/<code>` as a QR code; a signed-in phone opens it and approves,
which hands the phone's user to that page. Codes live 10 minutes, are
approved once and taken once. Approval is broadcast on `topic/1`, so the
waiting page moves on at once.

- [HaAuth.Plug](HaAuth.Plug.md): Plugs for routes
- [HaAuth.Router](HaAuth.Router.md): Routes for the login page and sign-in, added to a Phoenix router with
- [HaAuth.Session](HaAuth.Session.md): What HaAuth keeps in the Plug session, and reading it back.
- [HaAuth.Web.AuthController](HaAuth.Web.AuthController.md): The ways in (HA's OAuth, Kiosk Satellite, an approved QR code) and logout.
- [HaAuth.Web.LoginLive](HaAuth.Web.LoginLive.md): The login page, with all three ways in
- [HaAuth.Web.PairController](HaAuth.Web.PairController.md): The phone's side of the QR sign-in: `/pair/<code>` (behind sign-in) asks
to approve the screen showing that code; the POST hands the phone's user
to it.

