Livekit.AccessToken (Livekit v0.1.4)

View Source

Handles generation and management of Livekit access tokens.

Summary

Functions

Adds a grant to the token.

Creates a new AccessToken with the given API key and secret.

Generates a JWT token string.

Verifies a JWT token and returns its claims.

Sets the grants for the token.

Sets the identity for the token.

Sets metadata for the token.

Sets the name for the token.

Sets the TTL (time to live) for the token in seconds.

Types

t()

@type t() :: %Livekit.AccessToken{
  api_key: String.t() | nil,
  api_secret: String.t() | nil,
  grants: Livekit.Grants.t(),
  identity: String.t() | nil,
  metadata: String.t() | nil,
  name: String.t() | nil,
  ttl: integer() | nil
}

Functions

add_grant(token, grant)

Adds a grant to the token.

new(api_key, api_secret)

Creates a new AccessToken with the given API key and secret.

to_jwt(token)

Generates a JWT token string.

verify(token, api_key, api_secret)

@spec verify(String.t(), String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Verifies a JWT token and returns its claims.

Parameters

  • token: The JWT token to verify
  • api_key: The API key to verify against
  • api_secret: The API secret to verify with

Returns

  • {:ok, claims}: If the token is valid, returns the decoded claims
  • {:error, reason}: If the token is invalid

with_grants(token, grants)

Sets the grants for the token.

with_identity(token, identity)

Sets the identity for the token.

with_metadata(token, metadata)

Sets metadata for the token.

with_name(token, name)

Sets the name for the token.

with_ttl(token, ttl)

Sets the TTL (time to live) for the token in seconds.