SyntropyWeb.OperatorAuth (syntropy v0.2.0)

Copy Markdown

Session-based operator authentication for the mission control UI.

Credentials come from the environment (SYNTROPY_OPERATOR_PASSWORD, plus an optional SYNTROPY_OPERATOR_USER, default "operator"). Enforcement is required outside dev/test, mirroring SyntropyWeb.ApiAuth.required?/0.

Summary

Functions

LiveView mount guard: live_session ..., on_mount: {SyntropyWeb.OperatorAuth, :default}.

Validates a login attempt in constant time.

Functions

authenticated?(conn)

@spec authenticated?(Plug.Conn.t() | map()) :: boolean()

on_mount(atom, params, session, socket)

@spec on_mount(:default, map(), map(), Phoenix.LiveView.Socket.t()) ::
  {:cont, Phoenix.LiveView.Socket.t()} | {:halt, Phoenix.LiveView.Socket.t()}

LiveView mount guard: live_session ..., on_mount: {SyntropyWeb.OperatorAuth, :default}.

required?()

@spec required?() :: boolean()

session_key()

@spec session_key() :: String.t()

sign_in(conn)

@spec sign_in(Plug.Conn.t()) :: Plug.Conn.t()

sign_out(conn)

@spec sign_out(Plug.Conn.t()) :: Plug.Conn.t()

username()

@spec username() :: String.t()

validate_credentials(provided_username, provided_password)

@spec validate_credentials(String.t() | nil, String.t() | nil) ::
  :ok | {:error, :invalid}

Validates a login attempt in constant time.