Table of Contents

Class AccessToken

Namespace
Livekit.Server.Sdk.Dotnet
Assembly
LivekitApi.dll

Access tokens are required to connect to the server. Once information is filled out, create the token string with ToJwt(). See Access tokens and grants.

public class AccessToken
Inheritance
AccessToken
Inherited Members

Examples

var token = new AccessToken("api-key", "api-secret")
    .WithIdentity("participant-identity")
    .WithName("Participant name")
    .WithGrants(new VideoGrants { RoomJoin = true, Room = "my-room" })
    .WithTtl(TimeSpan.FromHours(1));
string jwt = token.ToJwt();

Constructors

AccessToken(string, string)

Creates a token signed with the given API key and secret.

public AccessToken(string apiKey = null, string apiSecret = null)

Parameters

apiKey string

API key; the LIVEKIT_API_KEY environment variable when omitted.

apiSecret string

API secret, at least 32 bytes long; the LIVEKIT_API_SECRET environment variable when omitted.

Exceptions

ArgumentException

The key or the secret is missing, or the secret is shorter than 32 bytes.

Properties

Claims

The claims of the token (identity, name, metadata, grants...), filled by the With* methods.

public ClaimsModel Claims { get; }

Property Value

ClaimsModel

Methods

ToJwt()

Generates the JWT token as a string.

public string ToJwt()

Returns

string

The signed JWT.

WithAttributes(Dictionary<string, string>)

Key/value attributes to attach to the participant.

public AccessToken WithAttributes(Dictionary<string, string> attributes)

Parameters

attributes Dictionary<string, string>

Key/value attributes attached to the participant.

Returns

AccessToken

This token, so calls can be chained.

WithExpiration(DateTime)

Used to specify an expiration time. If set, takes preference over the value set with WithTtl(TimeSpan).

public AccessToken WithExpiration(DateTime expiration)

Parameters

expiration DateTime

Absolute expiration time. A value of kind Unspecified is read as local time.

Returns

AccessToken

This token, so calls can be chained.

WithExpiration(DateTimeOffset)

Used to specify an expiration time, with an explicit offset (a DateTime of kind Unspecified would be read as local time). If set, takes preference over the value set with WithTtl(TimeSpan).

public AccessToken WithExpiration(DateTimeOffset expiration)

Parameters

expiration DateTimeOffset

Absolute expiration time.

Returns

AccessToken

This token, so calls can be chained.

WithGrants(VideoGrants)

Adds VideoGrants to this token.

public AccessToken WithGrants(VideoGrants grants)

Parameters

grants VideoGrants

Room permissions of the token holder: joining, publishing, subscribing, room administration...

Returns

AccessToken

This token, so calls can be chained.

WithIdentity(string)

Unique identity of the user, required for room join tokens.

public AccessToken WithIdentity(string identity)

Parameters

identity string

Identity of the participant, unique within the room.

Returns

AccessToken

This token, so calls can be chained.

WithInferenceGrants(InferenceGrants)

Adds InferenceGrants to this token.

public AccessToken WithInferenceGrants(InferenceGrants grants)

Parameters

grants InferenceGrants

Inference permissions.

Returns

AccessToken

This token, so calls can be chained.

WithKind(Kind)

Sets the kind of participant, which lets other participants and services tell agents, SIP callers, egress and ingress apart from standard users.

public AccessToken WithKind(ParticipantInfo.Types.Kind kind)

Parameters

kind ParticipantInfo.Types.Kind

Kind of participant: standard, egress, ingress, agent or SIP.

Returns

AccessToken

This token, so calls can be chained.

WithMetadata(string)

Custom metadata to be passed to participants.

public AccessToken WithMetadata(string metadata)

Parameters

metadata string

Free-form metadata attached to the participant and visible to the others.

Returns

AccessToken

This token, so calls can be chained.

WithName(string)

Display name of the participant, which the other participants see.

public AccessToken WithName(string name)

Parameters

name string

Display name shown to the other participants.

Returns

AccessToken

This token, so calls can be chained.

WithNotBefore(DateTime)

Date specifying the time before which this token is invalid. If not set, the token is valid immediately after creation. See RFC 7519.

public AccessToken WithNotBefore(DateTime notBefore)

Parameters

notBefore DateTime

Time before which the token is not valid. A value of kind Unspecified is read as local time.

Returns

AccessToken

This token, so calls can be chained.

WithNotBefore(DateTimeOffset)

Date specifying the time before which this token is invalid, with an explicit offset (a DateTime of kind Unspecified would be read as local time).

public AccessToken WithNotBefore(DateTimeOffset notBefore)

Parameters

notBefore DateTimeOffset

Time before which the token is not valid.

Returns

AccessToken

This token, so calls can be chained.

WithObservabilityGrants(ObservabilityGrants)

Adds ObservabilityGrants to this token.

public AccessToken WithObservabilityGrants(ObservabilityGrants grants)

Parameters

grants ObservabilityGrants

Observability permissions.

Returns

AccessToken

This token, so calls can be chained.

WithRoomConfig(RoomConfiguration)

Room configuration (agents to dispatch, egress, limits...) applied when this token creates the room.

public AccessToken WithRoomConfig(RoomConfiguration roomConfig)

Parameters

roomConfig RoomConfiguration

Room configuration: agents to dispatch, egress, participant limits...

Returns

AccessToken

This token, so calls can be chained.

WithRoomPreset(string)

Name of the room configuration preset to apply when this token creates the room.

public AccessToken WithRoomPreset(string roomPreset)

Parameters

roomPreset string

Name of the room configuration preset.

Returns

AccessToken

This token, so calls can be chained.

WithSha256(string)

For verifying the integrity of the message body.

public AccessToken WithSha256(string sha256)

Parameters

sha256 string

Base64 SHA-256 of the message body the token authenticates (used by webhooks).

Returns

AccessToken

This token, so calls can be chained.

WithSipGrants(SIPGrants)

Adds SIPGrants to this token.

public AccessToken WithSipGrants(SIPGrants grants)

Parameters

grants SIPGrants

SIP permissions: administering trunks and dispatch rules (Admin) or making calls (Call).

Returns

AccessToken

This token, so calls can be chained.

WithTtl(TimeSpan)

Amount of time the created token is valid for. Defaults to 6 hours.

public AccessToken WithTtl(TimeSpan ttl)

Parameters

ttl TimeSpan

How long the token stays valid after it is generated.

Returns

AccessToken

This token, so calls can be chained.