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
apiKeystringAPI key; the
LIVEKIT_API_KEYenvironment variable when omitted.apiSecretstringAPI secret, at least 32 bytes long; the
LIVEKIT_API_SECRETenvironment 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
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
attributesDictionary<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
expirationDateTimeAbsolute expiration time. A value of kind
Unspecifiedis 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
expirationDateTimeOffsetAbsolute expiration time.
Returns
- AccessToken
This token, so calls can be chained.
WithGrants(VideoGrants)
Adds VideoGrants to this token.
public AccessToken WithGrants(VideoGrants grants)
Parameters
grantsVideoGrantsRoom 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
identitystringIdentity 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
grantsInferenceGrantsInference 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
kindParticipantInfo.Types.KindKind 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
metadatastringFree-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
namestringDisplay 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
notBeforeDateTimeTime before which the token is not valid. A value of kind
Unspecifiedis 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
notBeforeDateTimeOffsetTime 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
grantsObservabilityGrantsObservability 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
roomConfigRoomConfigurationRoom 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
roomPresetstringName 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
sha256stringBase64 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
grantsSIPGrantsSIP 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
ttlTimeSpanHow long the token stays valid after it is generated.
Returns
- AccessToken
This token, so calls can be chained.