RFC 7635 third-party authorization access tokens.
What problem this solves
Some deployments let an authorization server mint temporary MAC keys instead of sharing user passwords with the TURN server. The ACCESS-TOKEN attribute carries an encrypted blob; this module mints and verifies those tokens (AES-256-GCM over a 20-byte MAC key, issue time, and lifetime) using the configured AEAD key and server name as additional authenticated data.
Opt-in via :third_party_auth application env. Long-term credentials and
MESSAGE-INTEGRITY (RFC 8489) remain the default path when disabled.
RFCs
Summary
Functions
Returns the 32-byte AEAD key from config, or nil when missing or invalid.
Returns the configured authorization-server URI, or nil.
Returns true when :third_party_auth is enabled and a valid AEAD key is configured.
Mints an encrypted access token for mac_key with lifetime_seconds validity.
Mints an encrypted access token using an explicit issue timestamp (Unix seconds).
Returns the configured server name used as GCM AAD, defaulting to :realm.
Verifies token and returns {:ok, mac_key} on success.
Verifies token and returns {:ok, mac_key} using an explicit GCM AAD server_name.
Functions
Returns the 32-byte AEAD key from config, or nil when missing or invalid.
Returns the configured authorization-server URI, or nil.
Returns true when :third_party_auth is enabled and a valid AEAD key is configured.
@spec mint(binary(), pos_integer(), binary(), binary()) :: binary()
Mints an encrypted access token for mac_key with lifetime_seconds validity.
Uses the current system time as the issue timestamp. See mint/5 to pin time
for testing.
Examples
iex> key = :crypto.hash(:sha256, "doctest-aead-key")
iex> server = "turn.example.com"
iex> mac_key = :crypto.strong_rand_bytes(20)
iex> token = Xirsys.XTurn.Auth.AccessToken.mint(mac_key, 60, key, server)
iex> {:ok, ^mac_key} = Xirsys.XTurn.Auth.AccessToken.verify(token, key, server)
Mints an encrypted access token using an explicit issue timestamp (Unix seconds).
Prefer mint/4 for production; this arity supports deterministic tests.
Returns the configured server name used as GCM AAD, defaulting to :realm.
Verifies token and returns {:ok, mac_key} on success.
Uses the configured server name as GCM AAD. Returns {:error, :invalid} when
decryption fails, the MAC key length is wrong, or the token is outside its lifetime.
Verifies token and returns {:ok, mac_key} using an explicit GCM AAD server_name.