PhoenixWebTransport.Token (phoenix_wtransport v0.1.0)

Copy Markdown View Source

Signs and verifies short-lived Phoenix.Token credentials for bridging HTTP session state into cookie-less WebTransport connections.

Because browsers send WebTransport CONNECT requests with credentials: "omit", Plug session cookies are not attached to the HTTP/3 handshake. Applications mint a signed token on the normal HTTPS/HTTP endpoint (see PhoenixWebTransport.Plug) and verify it in socket.connect/1 or a LiveView on_mount hook.

Summary

Functions

Default token lifetime in seconds.

Verifies a token minted by sign/3.

Functions

default_max_age()

@spec default_max_age() :: pos_integer()

Default token lifetime in seconds.

sign(context, claims, opts \\ [])

@spec sign(module() | Plug.Conn.t() | binary(), term(), keyword()) :: String.t()

Signs claims using Phoenix.Token.sign/4.

context may be a Phoenix.Endpoint, a Plug.Conn, or a secret_key_base binary. Options: :salt (default "phoenix_wtransport_connect"), :max_age.

verify(context, token, opts \\ [])

@spec verify(module() | Plug.Conn.t() | binary(), String.t() | nil, keyword()) ::
  {:ok, term()} | {:error, :missing | :invalid | :expired}

Verifies a token minted by sign/3.

Options: :salt (default "phoenix_wtransport_connect"), :max_age (default 60 seconds).