SeuraaEdge
v1
Docs/SDKs
SDKs

Integrate trusted .NET backends with Edge.

.NET Server SDK

Use the .NET server SDK in trusted backend code to issue channel tokens, publish events, query presence, and revoke tokens.

Create A Client

csharp
using Seuraa.Edge;

using var edge = new EdgeServerClient(new EdgeServerClientOptions
{
    AppKey = builder.Configuration["Seuraa:AppKey"]!,
    AppSecret = builder.Configuration["Seuraa:AppSecret"]!,
});

Keep AppSecret in backend configuration. Never expose it to browser or mobile clients.

Issue A Channel Token

The backend authenticates the user and decides which channel permissions to grant:

csharp
app.MapPost("/api/edge/token", (
    TokenRequest request,
    ClaimsPrincipal principal) =>
{
    var userId = principal.FindFirstValue(ClaimTypes.NameIdentifier)
        ?? throw new UnauthorizedAccessException();

    if (request.Channel != $"private:{userId}")
    {
        return Results.Forbid();
    }

    var session = edge.Auth.SignIn(new EdgeSignInRequest
    {
        Channel = request.Channel,
        ExpiresInSeconds = 60,
        Permissions = ["subscribe"],
        UserId = userId,
    });

    return Results.Ok(new
    {
        token = session.Token,
        tokenId = session.TokenId,
        expiresAt = session.ExpiresAt,
    });
});

Store TokenId when a session may need to be revoked before expiry.

Publish An Event

csharp
await edge.Channels.PublishAsync(
    "private:user-123",
    "notification.created",
    new { title = "Your report is ready" });

Provide a stable client event ID when retrying the same operation:

csharp
await edge.Channels.PublishAsync(
    "private:user-123",
    "notification.created",
    new { title = "Your report is ready" },
    new PublishOptions { ClientEventId = "notification-456" });

Presence

csharp
var presence = await edge.Channels.PresenceAsync(
    "presence:document-123");

Console.WriteLine(presence.Count);

Presence member identifiers come from the UserId claim:

csharp
var session = edge.Auth.SignIn(new EdgeSignInRequest
{
    Channel = "presence:document-123",
    Permissions = ["subscribe"],
    UserId = "user-123",
});

Presence responses contain member IDs only.

Revoke A Token

csharp
await edge.Auth.RevokeAsync(
    session.TokenId,
    new RevokeTokenOptions { TtlSeconds = 3600 });

Set the revocation TTL to cover the token's remaining lifetime.

Errors

Failed Edge requests throw EdgeServerException. It exposes the HTTP StatusCode and raw ResponseBody for application logging and error mapping.