PhoenixWebTransport.Plug (phoenix_wtransport v0.1.0)

Copy Markdown View Source

Optional Phoenix Endpoint / Router Plug for HTTP/3 discovery and cookie-less WebTransport session token minting.

Features:

  • Advertises the active WebTransport/HTTP3 port via Alt-Svc headers
  • Serves POST /_wt/token (configurable) using the browser's normal Plug session cookie to mint a short-lived signed PhoenixWebTransport.Token without exposing raw cookies or tokens in query strings

Example

# In MyAppWeb.Endpoint (after Plug.Session, before MyAppWeb.Router)
plug PhoenixWebTransport.Plug,
  token_path: "/_wt/token",
  claims: fn conn ->
    case Plug.Conn.get_session(conn, :current_user_id) do
      nil -> {:error, :unauthorized}
      user_id -> {:ok, %{"user_id" => user_id, "live_socket_id" => Plug.Conn.get_session(conn, "live_socket_id")}}
    end
  end