Canton.Ledger.Auth 0.1.5-preview.1

Prefix Reserved
This is a prerelease version of Canton.Ledger.Auth.
dotnet add package Canton.Ledger.Auth --version 0.1.5-preview.1
                    
NuGet\Install-Package Canton.Ledger.Auth -Version 0.1.5-preview.1
                    
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="Canton.Ledger.Auth" Version="0.1.5-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Canton.Ledger.Auth" Version="0.1.5-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Canton.Ledger.Auth" />
                    
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 Canton.Ledger.Auth --version 0.1.5-preview.1
                    
#r "nuget: Canton.Ledger.Auth, 0.1.5-preview.1"
                    
#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 Canton.Ledger.Auth@0.1.5-preview.1
                    
#: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=Canton.Ledger.Auth&version=0.1.5-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Canton.Ledger.Auth&version=0.1.5-preview.1&prerelease
                    
Install as a Cake Tool

Canton.Ledger.Auth

Authentication providers for Canton participant nodes. Supplies bearer tokens to the gRPC and PQS clients via the ITokenProvider interface.

Key Types

Type Purpose
ITokenProvider Interface — Task<string> GetTokenAsync(CancellationToken)
ITokenProvider.None Static singleton signaling unauthenticated access (no Authorization header)
StaticTokenProvider Returns a fixed token string. Use for short-lived processes or testing
ClientCredentialsProvider OAuth2 client-credentials flow with thread-safe TTL cache (SemaphoreSlim + Volatile reads/writes)
ClientCredentialsOptions Config: Domain, ClientId, ClientSecret, Audience, TokenEndpoint, SafetyMargin

Usage

Client-credentials (OAuth2) via DI

services.AddCantonAuth(configuration.GetSection("Canton:Auth"));
{
  "Canton": {
    "Auth": {
      "Domain": "dev-peaceful.eu.auth0.com",
      "ClientId": "my-client-id",
      "ClientSecret": "my-client-secret",
      "Audience": "https://canton.network/"
    }
  }
}

Domain accepts either a bare hostname (e.g. dev-peaceful.eu.auth0.com) or an absolute http/https URL (e.g. https://auth.example.com, or https://auth.example.com/tenant-a for per-tenant subpaths). If Domain is a bare hostname, it is treated as https://{hostname}. If it is an absolute http/https URL, that URL is used as the base. In both cases, /oauth/token is appended, preserving any existing path (https://auth.example.com/tenant-a → https://auth.example.com/tenant-a/oauth/token). Userinfo, query, and fragments are rejected. ClientCredentialsProvider caches tokens until expires_in - SafetyMargin (default 30s) and concurrent callers share a single HTTP request during refresh.

To override the token endpoint (e.g., non-standard OAuth2 servers like Keycloak's /realms/{realm}/protocol/openid-connect/token):

{
  "Canton": {
    "Auth": {
      "TokenEndpoint": "https://custom.example.com/oauth/token",
      "ClientId": "...",
      "ClientSecret": "..."
    }
  }
}

Static token via DI

services.AddCantonStaticAuth("eyJ...");

Action-based configuration

services.AddCantonAuth(options =>
{
    options.Domain = "https://auth.example.com";
    options.ClientId = "my-client-id";
    options.ClientSecret = "my-client-secret";
    options.Audience = "https://canton.network/";
});

Registration precedence

All methods use TryAddSingleton — the first registration wins. Register explicit providers before calling AddLedgerClient/AddAdminClient to override auto-registration.

Unauthenticated access

When no ITokenProvider is registered, AddLedgerClient/AddAdminClient register ITokenProvider.None as a default. Clients detect this and skip the Authorization header. Use this for local development with unauthenticated Canton nodes.

Internals

  • IHttpClientFactory named client "CantonAuth" — no using on the HttpClient (factory manages handler lifetime)
  • TimeProvider for testable time (pass FakeTimeProvider in tests)
  • Volatile.Read/Volatile.Write for cache fields — write order: token before expiry (matches read order)
  • Validates expires_in > 0 and access_token non-empty after deserialization
  • Token endpoint is resolved once at construction — unresolvable options (no TokenEndpoint, invalid Domain) throw InvalidOperationException when the provider is constructed, not at the first token request
  • Canton.Ledger.Grpc.Client — gRPC client that consumes ITokenProvider
  • Canton.Ledger.Pqs.Client — PQS query client
Product Compatible and additional computed target framework versions.
.NET 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. 
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
0.1.5-preview.1 114 6/25/2026
0.1.4-preview.1 72 6/15/2026