> ## Documentation Index
> Fetch the complete documentation index at: https://docs.didit.me/llms.txt
> Use this file to discover all available pages before exploring further.

# C# and .NET SDK for KYC, AML and Transactions

> Quickstart for the official Didit C# and .NET SDK: async typed calls for the server APIs, dependency injection, webhook verification and token checks.

The official Didit library for C# and .NET. It targets .NET 8 and .NET Standard 2.0, and every API method is `async`. On .NET Framework, use C# 11 or later. See the [server SDKs overview](https://docs.didit.me/integration/server-sdks/overview.md) for what every SDK shares.

## Install

```bash theme={null}
dotnet add package Didit
```

For ASP.NET Core dependency injection, also add `Didit.Extensions.DependencyInjection` and register the client with `services.AddDidit()`.

The packages are [`Didit`](https://www.nuget.org/packages/Didit) and [`Didit.Extensions.DependencyInjection`](https://www.nuget.org/packages/Didit.Extensions.DependencyInjection) on NuGet. Their source and changelog are in [didit-protocol/sdk-dotnet](https://github.com/didit-protocol/sdk-dotnet) on GitHub.

## Configure the client

`new DiditClient()` reads `DIDIT_API_KEY` from the environment. Pass `DiditClientOptions` to override it, or to set the organization and application ids that application-scoped calls (cases, networks, regulatory reports) need. Create one client and reuse it.

```csharp theme={null}
using System;
using Didit;

using var client = new DiditClient(new DiditClientOptions
{
    ApiKey = Environment.GetEnvironmentVariable("DIDIT_API_KEY"),
    OrganizationId = Environment.GetEnvironmentVariable("DIDIT_ORGANIZATION_ID"),
    ApplicationId = Environment.GetEnvironmentVariable("DIDIT_APPLICATION_ID"),
    Timeout = TimeSpan.FromSeconds(30),
    MaxRetries = 2,
});

// Options for a single call.
var decision = await client.Sessions.RetrieveDecisionAsync(
    "11111111-2222-3333-4444-555555555555",
    requestOptions: new RequestOptions { Timeout = TimeSpan.FromSeconds(5), MaxRetries = 0 });
Console.WriteLine(decision.Status);
```

Required request properties are `required`, so a missing one fails to compile. Optional ones you leave unset are not sent.

## Create a session

Create a [verification session](https://docs.didit.me/sessions-api/create-session.md) for a workflow and send your user to its URL.

```csharp theme={null}
using System;
using Didit;

using var client = new DiditClient();

var session = await client.Sessions.CreateAsync(new SessionsCreateParams
{
    WorkflowId = "11111111-2222-3333-4444-555555555555",
    VendorData = "user-123",
    Callback = "https://example.com/verification/done",
});
Console.WriteLine(session.Url);
```

## Read the decision

When the user finishes (or when the webhook arrives), [read the decision](https://docs.didit.me/sessions-api/retrieve-session.md). Every feature result is a list with one entry per workflow node.

```csharp theme={null}
using System;
using Didit;

using var client = new DiditClient();

var decision = await client.Sessions.RetrieveDecisionAsync("11111111-2222-3333-4444-555555555555");
Console.WriteLine(decision.Status);
foreach (var verification in decision.IdVerifications ?? Array.Empty<SessionDecisionIdVerifications>())
{
    Console.WriteLine(verification.Status);
}
```

## Verify a webhook

Pass the raw body, exactly as received, and a way to read the request headers. `DiditWebhooks.Verify` throws `WebhookVerificationException` for anything that is not a valid, fresh delivery, and returns a typed event otherwise.

```csharp theme={null}
using System;
using Didit;

var secret = Environment.GetEnvironmentVariable("DIDIT_WEBHOOK_SECRET") ?? "";

int HandleWebhook(string rawBody, Func<string, string?> header)
{
    try
    {
        var evt = DiditWebhooks.Verify(rawBody, header, secret);
        if (evt is SessionStatusUpdatedEvent updated)
        {
            Console.WriteLine($"{updated.SessionId} {updated.Status}");
        }
        return 200;
    }
    catch (WebhookVerificationException error)
    {
        Console.WriteLine($"rejected: {error.Reason}");
        return 400;
    }
}
```

In an ASP.NET Core minimal API, read the body with a `StreamReader` and pass `name => request.Headers[name].FirstOrDefault()`. While you rotate the secret, pass both: `new[] { newSecret, oldSecret }`. See [Webhooks](https://docs.didit.me/integration/webhooks.md) for the events and the signature scheme.

## Screen a transaction

Submit a payment, withdrawal or crypto transfer to [transaction monitoring](https://docs.didit.me/transaction-monitoring/overview.md); the response carries its status and risk score.

```csharp theme={null}
using System;
using Didit;

using var client = new DiditClient();

var transaction = await client.Transactions.CreateAsync(new TransactionsCreateParams
{
    TransactionId = "txn-1001",
    TransactionCategory = "finance",
    TransactionDetails = new()
    {
        Direction = "outbound",
        Amount = 1500,
        Currency = "EUR",
    },
    Subject = new()
    {
        EntityType = "individual",
        VendorData = "user-123",
        FullName = "Maria Garcia",
    },
});
Console.WriteLine($"{transaction.Status} {transaction.Score}");
```

## Verify Authentication tokens

`Authentication` checks the access tokens your [Authentication](https://docs.didit.me/authentication/overview.md) issuer signs, in your backend, without calling Didit for each request. It also exchanges codes, refreshes tokens, checks and revokes sessions, and runs step-ups.

> [!NOTE]
>
> Token verification makes the checks in [Verify a token on your server](https://docs.didit.me/authentication/tokens-and-jwks.md#verify-a-token-on-your-server), against your application's issuer and signing keys.

```csharp theme={null}
using System;
using System.Threading.Tasks;
using Didit;

// The publishable key (pk_live_... or pk_test_...) carries your issuer URL.
var auth = Authentication.FromPublishableKey("pk_live_...");

async Task<string?> CurrentUserAsync(string accessToken)
{
    try
    {
        var claims = await auth.VerifyAccessTokenAsync(accessToken, audience: "your-application-id");
        return claims.Subject;
    }
    catch (TokenVerificationException error)
    {
        Console.WriteLine($"rejected: {error.Reason}");
        return null;
    }
}
```

## Errors

```csharp theme={null}
using System;
using Didit;

using var client = new DiditClient();

try
{
    await client.Sessions.RetrieveDecisionAsync("11111111-2222-3333-4444-555555555555");
}
catch (NotFoundException)
{
    Console.WriteLine("no such session");
}
catch (ApiStatusException error)
{
    Console.WriteLine($"{error.StatusCode} {error.RequestId}");
}
```

## Lists and files

```csharp theme={null}
using System;
using Didit;

using var client = new DiditClient();

// Lists page through every result.
await foreach (var session in await client.Sessions.ListAsync(new SessionsListParams { Status = "Approved" }))
{
    Console.WriteLine(session.SessionId);
}

// Uploads take FileUpload.FromPath, FromBytes or FromStream.
var result = await client.IdVerification.VerifyAsync(new IdVerificationVerifyParams
{
    FrontImage = FileUpload.FromPath("id-front.jpg"),
    BackImage = FileUpload.FromPath("id-back.jpg"),
});
Console.WriteLine(result.IdVerification?.Status);
```

Server endpoint pages of the [API reference](https://docs.didit.me/api-reference/overview.md) have a .NET sample for their operation, except for the endpoints and fields that no 1.0.1 release has yet, named in the [overview](https://docs.didit.me/integration/server-sdks/overview.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.