Class WebhookReceiver
- Namespace
- Livekit.Server.Sdk.Dotnet
- Assembly
- LivekitApi.dll
Receives the webhook events LiveKit posts: verifies the token of the Authorization header and the
SHA-256 of the body, then parses the WebhookEvent.
public class WebhookReceiver : TokenVerifier
- Inheritance
-
WebhookReceiver
- Inherited Members
Examples
var receiver = new WebhookReceiver("api-key", "api-secret");
// ASP.NET Core minimal API. Pass the raw body: LiveKit signs its SHA-256.
app.MapPost("/livekit/webhook", async (HttpRequest request) =>
{
using var body = new MemoryStream();
await request.Body.CopyToAsync(body);
WebhookEvent webhookEvent = receiver.Receive(
body.ToArray(),
request.Headers.Authorization.ToString()
);
Console.WriteLine($"{webhookEvent.Event} in room {webhookEvent.Room?.Name}");
return Results.Ok();
});
Constructors
WebhookReceiver(string, string)
Creates a receiver for webhooks signed with the given API key and secret.
public WebhookReceiver(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.
WebhookReceiver(string, string, TimeSpan?)
Creates a receiver with a custom clock tolerance for the token lifetime.
public WebhookReceiver(string apiKey, string apiSecret, TimeSpan? leeway)
Parameters
apiKeystringAPI key; the
LIVEKIT_API_KEYenvironment variable when null.apiSecretstringAPI secret, at least 32 bytes long; the
LIVEKIT_API_SECRETenvironment variable when null.leewayTimeSpan?Clock tolerance applied to the token lifetime; DefaultLeeway when null.
Exceptions
- ArgumentException
The key or the secret is missing, or the secret is shorter than 32 bytes.
Methods
Receive(byte[], string, bool, bool)
Verifies a webhook request and parses its event, from the raw bytes of the body, which is what LiveKit signs. Prefer this overload.
public WebhookEvent Receive(byte[] body, string authHeader = null, bool skipAuth = false, bool ignoreUnknownFields = true)
Parameters
bodybyte[]The raw bytes of the posted body.
authHeaderstringValue of the
Authorizationheader of the request.skipAuthboolTrue to skip the token and SHA-256 checks.
ignoreUnknownFieldsboolTrue to ignore the fields this version of the SDK does not know, so events from newer servers still parse.
Returns
- WebhookEvent
The decoded event.
Exceptions
- ArgumentNullException
bodyis null.- Exception
The header is empty, or the SHA-256 of the body does not match the token.
- SecurityTokenException
The token has a wrong signature or issuer, or is expired.
- ArgumentException
The header is not a well-formed JWT (
SecurityTokenMalformedException).- InvalidJsonException
The body is not valid JSON.
- InvalidProtocolBufferException
The body is not a webhook event, or has unknown fields while
ignoreUnknownFieldsis false.
Receive(string, string, bool, bool)
Verifies a webhook request and parses its event, from the body as a string. The text is encoded as UTF-8 again to check its SHA-256, so it must be exactly what LiveKit posted; the Receive(byte[], string, bool, bool) overload avoids that conversion.
public WebhookEvent Receive(string body, string authHeader = null, bool skipAuth = false, bool ignoreUnknownFields = true)
Parameters
bodystringThe posted body, as text.
authHeaderstringValue of the
Authorizationheader of the request.skipAuthboolTrue to skip the token and SHA-256 checks.
ignoreUnknownFieldsboolTrue to ignore the fields this version of the SDK does not know, so events from newer servers still parse.
Returns
- WebhookEvent
The decoded event.
Exceptions
- ArgumentNullException
bodyis null.- Exception
The header is empty, or the SHA-256 of the body does not match the token.
- SecurityTokenException
The token has a wrong signature or issuer, or is expired.
- ArgumentException
The header is not a well-formed JWT (
SecurityTokenMalformedException).- InvalidJsonException
The body is not valid JSON.
- InvalidProtocolBufferException
The body is not a webhook event, or has unknown fields while
ignoreUnknownFieldsis false.