PhoenixKit.API.Confirm.Token (phoenix_kit v2.63.0)

Copy Markdown View Source

The confirmation code string of a dangerous API operation: ct_<row uuid>_<mac>.

mac is the first 24 bytes of HMAC-SHA256(key, "api-confirm:" <> uuid), base64url without padding (32 characters), where key is derived from the host's secret_key_base. The code proves nothing by itself: the row it names says what it was issued for, and the executor checks that against the request. Anyone who does not know the secret cannot make a code for a row.

The secret is looked up as config :phoenix_kit, :secret_key_base, then the parent endpoint's, then core's own endpoint's (the same sources as the storage URL signer), and must be at least 32 bytes. With no secret nothing is signed: sign/2 answers {:error, :no_secret} and the flow refuses to issue a code (never a predictable one).

Summary

Functions

The application's secret, or nil when none of the sources has a usable one.

Signs a row uuid. secret defaults to the application's.

Checks a code and returns the row uuid it names. Never raises.

Functions

secret()

@spec secret() :: String.t() | nil

The application's secret, or nil when none of the sources has a usable one.

sign(uuid, secret \\ secret())

@spec sign(String.t(), String.t() | nil) :: {:ok, String.t()} | {:error, :no_secret}

Signs a row uuid. secret defaults to the application's.

verify(token, secret \\ secret())

@spec verify(term(), String.t() | nil) :: {:ok, String.t()} | :error

Checks a code and returns the row uuid it names. Never raises.