ScoriaWeb.DashboardScope (scoria v0.1.3)

Copy Markdown View Source

Host-authenticated tenant scope for the embedded Scoria dashboard.

Use this module when a mounted /scoria dashboard needs trusted tenant and actor values from the host Phoenix app. Host apps own authentication, authorization, tenant membership, role values, and policy decisions. Scoria normalizes the resulting scope, assigns it to dashboard LiveViews, and fails closed when no trusted tenant scope is asserted.

Query params do not choose tenants. Public params and route values may be useful UI hints for selecting a run, trace, incident, or connector after mount, but tenant authority must come from the host-authenticated scope.

defmodule MyAppWeb.ScoriaDashboardScope do
  @behaviour ScoriaWeb.DashboardScope.Resolver

  @impl true
  def resolve(_params, _session, socket) do
    account = socket.assigns.current_account
    user = socket.assigns.current_user

    {:ok,
     %{
       tenant_id: account.id,
       actor_id: user.id,
       display_tenant: account.name
     }}
  end
end

The default resolver reads normalized scope keys from socket assigns and session data; it ignores query params as tenant authority.

See guides/ownership-boundary.md for the full Scoria-vs-host responsibility table and guides/getting-started.md for the dashboard mount sequence.

Summary

Functions

Normalize the default host session keys into dashboard scope.

Normalize explicit dashboard scope attrs into a struct or raise.

Resolve dashboard scope from the default resolver, resolver module, or MFA tuple.

Types

t()

@type t() :: %ScoriaWeb.DashboardScope{
  actor_id: String.t() | nil,
  display_tenant: String.t() | nil,
  session_id: String.t() | nil,
  tenant_id: String.t()
}

Functions

from_session(session)

Normalize the default host session keys into dashboard scope.

new!(scope)

Normalize explicit dashboard scope attrs into a struct or raise.

resolve(resolver, params, session, socket)

Resolve dashboard scope from the default resolver, resolver module, or MFA tuple.