Token signing, verification, and URL construction for file serving.
Uses Phoenix.Token to create signed tokens that encode a session ID,
allowing the Omni.UI.Files.Plug to authorize access without shared state.
Configuration
config :omni_ui, files_url_prefix: "/omni_files"The :url_prefix defaults to "/omni_files" and should match the path
where Omni.UI.Files.Plug is mounted in the router.
Summary
Functions
Builds a full file URL path with a signed token.
Signs a session ID into a token for use in file URLs.
Verifies a signed file token, returning the session ID.
Functions
@spec file_url( atom() | Plug.Conn.t() | Phoenix.LiveView.Socket.t(), String.t(), String.t() ) :: String.t()
Builds a full file URL path with a signed token.
Examples
url = URL.file_url(socket.endpoint, session_id, "dashboard.html")
# => "/omni_files/SFMyNT.../dashboard.html"
@spec sign_token(atom() | Plug.Conn.t() | Phoenix.LiveView.Socket.t(), String.t()) :: String.t()
Signs a session ID into a token for use in file URLs.
The endpoint argument accepts an endpoint module, a Plug.Conn, or a
Phoenix.LiveView.Socket — any context valid for Phoenix.Token.sign/4.
Examples
token = URL.sign_token(socket.endpoint, session_id)
token = URL.sign_token(conn, session_id)
@spec verify_token( atom() | Plug.Conn.t() | Phoenix.LiveView.Socket.t(), String.t(), keyword() ) :: {:ok, String.t()} | {:error, :expired | :invalid}
Verifies a signed file token, returning the session ID.
Options
:max_age— maximum token age in seconds (default: 86400 = 24 hours)
Examples
{:ok, session_id} = URL.verify_token(conn, token)
{:error, :expired} = URL.verify_token(conn, token, max_age: 1)