Descope 1.8.0

dotnet add package Descope --version 1.8.0
                    
NuGet\Install-Package Descope -Version 1.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Descope" Version="1.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Descope" Version="1.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Descope" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Descope --version 1.8.0
                    
#r "nuget: Descope, 1.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Descope@1.8.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Descope&version=1.8.0
                    
Install as a Cake Addin
#tool nuget:?package=Descope&version=1.8.0
                    
Install as a Cake Tool

Descope .NET SDK

A .NET SDK for integrating with the Descope authentication and user management platform.

Installation

dotnet add package Descope

Client Configuration

Configure the Descope client using DescopeClientOptions:

var options = new DescopeClientOptions
{
    ProjectId = "your-project-id",           // Required
    ManagementKey = "your-management-key",   // Optional, for management APIs
    AuthManagementKey = "your-auth-key",     // Optional, for accessing disabled auth APIs
    BaseUrl = "https://api.descope.com",     // Optional, auto-detected from project ID
    FgaCacheUrl = "https://fga.example.com", // Optional, if using the Descope FGA Cache Docker Container
    IsUnsafe = false,                        // Optional, for dev/test only
    JwksCacheDuration = TimeSpan.FromMinutes(5) // Optional, how long public signing keys are cached (default: 5 minutes)
};

Creating the Client

services.AddDescopeClient(new DescopeClientOptions
{
    ProjectId = "your-project-id",
    ManagementKey = "your-management-key"
});

// Inject IDescopeClient in your services
public class MyService
{
    private readonly IDescopeClient _client;
    
    public MyService(IDescopeClient client)
    {
        _client = client;
    }
}

Using Factory (Instance-based)

var client = DescopeManagementClientFactory.Create(new DescopeClientOptions
{
    ProjectId = "your-project-id",
    ManagementKey = "your-management-key"
});

Usage Examples

Authentication API Call

// Verify a magic link token
var response = await client.Auth.V1.Magiclink.Verify.PostAsync(
    new VerifyMagicLinkRequest { Token = "magic-link-token" });

Management API V1 Call

// Create a test user
var user = await client.Mgmt.V1.User.Create.Test.PostAsync(
    new CreateUserRequest
    {
        Identifier = "user@example.com",
        Email = "user@example.com",
        VerifiedEmail = true
    });

Management API V2 Call

// Search users
var searchResponse = await client.Mgmt.V2.User.Search.PostAsync(
    new SearchUsersRequest { Limit = 10 });

Management Flows

Management flows allow you to run server-side flows with custom input and receive dynamic output. The SDK provides a convenient extension method that deserializes the output as JSON for easy access.

// Run a management flow with custom input
var request = new RunManagementFlowRequest
{
    FlowId = "my-management-flow",
    Options = new ManagementFlowOptions
    {
        Input = new ManagementFlowOptions_input
        {
            AdditionalData = new Dictionary<string, object>
            {
                { "email", "user@example.com" },
                { "customParam", "customValue" }
            }
        }
    }
};

var response = await client.Mgmt.V1.Flow.Run.PostWithJsonOutputAsync(request);

// Access JSON properties directly using JsonElement
var root = response.OutputJson!.Value;
var email = root.GetProperty("email").GetString();

// Access nested objects using standard JsonElement methods
var greeting = root.GetProperty("obj").GetProperty("greeting").GetString();
var count = root.GetProperty("obj").GetProperty("count").GetInt32();
var enabled = root.GetProperty("obj").GetProperty("enabled").GetBoolean();

Token Validation

The SDK provides three methods for working with session tokens:

ValidateSessionAsync

Validates a session JWT locally using cached public keys. The public signing keys (JWKS) are fetched from the server and cached, so most validations do not make a network call.

var token = await client.Auth.ValidateSessionAsync(sessionJwt);
// Returns Token with claims, subject, expiration, etc.
Public key (JWKS) caching

Fetched keys are cached for DescopeClientOptions.JwksCacheDuration (default 5 minutes). Once the duration elapses, the next validation refreshes the keys; refreshes are lazy (triggered on the next validation), not on a background timer. To reduce key-fetch requests on high-traffic services, increase the duration:

var options = new DescopeClientOptions
{
    ProjectId = "your-project-id",
    JwksCacheDuration = TimeSpan.FromMinutes(30)
};

Raising this value is safe even during key rotation: if a token is signed with a key ID that is not already cached, the SDK performs an immediate key re-fetch (bypassing the cache duration) and retries validation once, so tokens from newly rotated keys are accepted right away. JwksCacheDuration must be greater than zero.

Note: For the cache to persist across requests, reuse a single IDescopeClient instance. The DI registration (AddDescopeClient) registers it as a singleton for you.

RefreshSessionAsync

Refreshes an expired session using a refresh JWT. This method makes a remote API call to generate a new session token.

var newToken = await client.Auth.RefreshSessionAsync(refreshJwt);
// Returns a new session Token with updated expiration

ValidateAndRefreshSession

Attempts to validate the session JWT first (locally), and if that fails or the session is empty, falls back to refreshing using the refresh JWT (remote call).

var token = await client.Auth.ValidateAndRefreshSession(sessionJwt, refreshJwt);
// Returns valid Token, using local validation when possible

Performance Note: Validation calls (ValidateSessionAsync, ValidateAndRefreshSession) are highly efficient as they use locally cached public keys. Only RefreshSessionAsync and the refresh fallback in ValidateAndRefreshSession make remote API calls.

Authenticated User Operations

Some authentication operations require an authenticated user context and must be called with a refresh JWT. For these operations, use the PostWithJwt extension methods that explicitly require the refresh token.

Example: Update User Email

// Update user email using magic link (requires refresh JWT)
var response = await client.Auth.V1.Magiclink.Update.Email.PostWithJwtAsync(
    new UpdateUserEmailMagicLinkRequest
    {
        Email = "newemail@example.com",
        RedirectUrl = "https://myapp.com/verify"
    },
    refreshJwt);

Other operations requiring PostWithJwt include, among others: updating phone numbers, passwords, TOTP settings, WebAuthn devices, and getting user details via the /me endpoint.

ASP.NET OIDC Integration

For ASP.NET Core applications, use the AddDescopeOidcAuthentication extension method to integrate Descope as your Identity Provider (IdP) using OpenID Connect (OIDC):

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddDescopeOidcAuthentication(options =>
    {
        options.ProjectId = "your-project-id";
    });

See the OIDC Demo Application for a complete working example with additional customization options.

For Maintainers

If you're maintaining or contributing to this SDK, see the Maintainer Guide for detailed information about code generation, extension methods, testing, and development workflows.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.0 313 7/15/2026
1.7.1 3,656 7/5/2026
1.7.0 680 6/22/2026
1.6.1 4,795 5/13/2026
1.6.0 3,121 3/23/2026
1.5.1 496 3/16/2026
1.5.0 1,231 2/26/2026
1.4.0 191 2/25/2026
1.3.4 457 2/20/2026
1.3.3 860 2/8/2026
1.3.2 137 2/5/2026
1.3.1 135 2/5/2026
1.3.0 1,486 1/18/2026
1.2.0 280 12/30/2025
1.1.0 147 12/29/2025
1.0.1 2,259 12/16/2025
1.0.0 401 12/14/2025
0.6.99 552 12/16/2025
0.6.9 378 12/12/2025
0.6.8 576 12/8/2025
Loading failed