LiveKit.Auth (LiveKit v0.1.0)

Copy Markdown View Source

Creates the short-lived administrative tokens used by LiveKit service calls.

Every service call signs its own token carrying only the grants that call needs, so nothing here hardcodes a universal "admin everything" grant:

iex> client = LiveKit.Client.new!(url: "http://localhost:7880", api_key: "k", api_secret: "s")
iex> {:ok, jwt} = LiveKit.Auth.service_token(client, video_grant: %LiveKit.Grants.Video{room_list: true})
iex> is_binary(jwt)
true

Tokens are valid for 600 seconds. This module deliberately knows nothing about HTTP; LiveKit.Twirp combines it with the transport.

Summary

Functions

Signs a service token for a client.

The lifetime of service tokens, in seconds.

Functions

service_token(client, opts \\ [])

@spec service_token(
  LiveKit.Client.t(),
  keyword()
) :: {:ok, String.t()} | {:error, LiveKit.Error.t()}

Signs a service token for a client.

Options

  • :video_grant, :sip_grant, :agent_grant - individual grant structs.
  • :grants - keyword list of video:, sip: and/or agent: grants; a convenient shape for service modules that pass grants through.
  • :identity - optional identity, encoded as sub.
  • :ttl - lifetime in seconds. Defaults to 600.
  • :clock - zero-arity function returning Unix seconds, for tests.

At least one grant is required.

Examples

iex> client = LiveKit.Client.new!(url: "http://localhost:7880", api_key: "k", api_secret: "s")
iex> {:ok, _jwt} = LiveKit.Auth.service_token(client, grants: [video: %LiveKit.Grants.Video{room_admin: true}])
iex> {:error, error} = LiveKit.Auth.service_token(client, [])
iex> error.type
:authentication

service_token_ttl()

@spec service_token_ttl() :: pos_integer()

The lifetime of service tokens, in seconds.

Examples

iex> LiveKit.Auth.service_token_ttl()
600