Skip to main content

C# Backend SDK

Category
SDK
Published

We've released a new backend SDK for C#! Here's a quick overview of its capabilities and some resources to help you get started.

Check out the new server-side C# SDK right here!

With this launch, C# developers can more easily interface with the Clerk Backend API to manage users, organizations, and sessions.

Clerk Backend API call
using Clerk.BackendAPI;
using Clerk.BackendAPI.Models.Operations;
using Clerk.BackendAPI.Models.Components;

var sdk = new ClerkBackendApi(bearerAuth: "<YOUR_BEARER_TOKEN_HERE>");

var res = await sdk.EmailAddresses.GetAsync(emailAddressId: "email_address_id_example");

// handle response

This release also makes it straightforward to authenticate backend requests in ASP.NET, Blazor, and other C# web frameworks:

authenticateRequest in action
using Clerk.BackendAPI.Helpers.Jwks;
using System;
using System.Net.Http;
using System.Threading.Tasks;

public class UserAuthentication
{
    public static async Task<bool> IsSignedInAsync(HttpRequestMessage request)
    {
        var options = new AuthenticateRequestOptions(
            secretKey: Environment.GetEnvironmentVariable("CLERK_SECRET_KEY"),
            authorizedParties: new string[] { "https://example.com" }
        );

        var requestState = await AuthenticateRequest.AuthenticateRequestAsync(request, options);

        return requestState.isSignedIn();
    }
}

You can use NuGet to install the new Clerk.BackendAPI module via dotnet add package Clerk.BackendAPI. To help you from there, we've prepared detailed reference documentation in the SDK's GitHub repository.

Special thanks to Speakeasy for partnering with us on this SDK release 🎉!