AffinidiTdk.AuthProvider 1.1.1

dotnet add package AffinidiTdk.AuthProvider --version 1.1.1
                    
NuGet\Install-Package AffinidiTdk.AuthProvider -Version 1.1.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="AffinidiTdk.AuthProvider" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AffinidiTdk.AuthProvider" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="AffinidiTdk.AuthProvider" />
                    
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 AffinidiTdk.AuthProvider --version 1.1.1
                    
#r "nuget: AffinidiTdk.AuthProvider, 1.1.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 AffinidiTdk.AuthProvider@1.1.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=AffinidiTdk.AuthProvider&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=AffinidiTdk.AuthProvider&version=1.1.1
                    
Install as a Cake Tool

AffinidiTdk.AuthProvider

This is a .NET TDK package which generates authorisation tokens to initialise TDK clients to access Affinidi services.

Requirements

  • .NET 8 SDK (minimum version: 8.0.400)
  • Compatible OS: Windows, macOS, or Linux

You can check your installed version using:

dotnet --version

Features

  • JWT Validation: Validate JWT tokens with a public key fetched from the API Gateway.
  • Project Scoped Tokens: Fetch project-scoped tokens to interact with Affinidi services.

Installation

To use it in your project, you can install it via NuGet:

dotnet add package AffinidiTdk.AuthProvider

To get ProjectScopedToken you need to initialize AuthProvider. Please check our docs how to obtain required secrets:

Thread Safety

The AuthProvider class is thread-safe and designed for high-concurrency environments:

  • Internally synchronizes token generation using a lock.
  • Automatically caches tokens and refreshes only when expired.
  • You can safely reuse a single AuthProvider instance across multiple threads or HTTP requests.
  • No additional locking or synchronization is required.

Token Management

You can create one shared AuthProvider instance and pass its token generator to multiple API clients (e.g., Wallets, IAM):

using AffinidiTdk.AuthProvider;

AuthProvider authProvider = new AuthProvider(new AuthProviderParams
{
    ProjectId = "PROJECT_ID",
    TokenId = "TOKEN_ID",
    PrivateKey = "PRIVATE_KEY",
    KeyId = "KEY_ID", // [OPTIONAL] unless unique value used on for the PAT
    Passphrase = "PASSPHRASE" // [OPTIONAL] unless private key is encrypted
});

❗️When you call:

string token = await authProvider.FetchProjectScopedTokenAsync();
  • If a valid (non-expired) token is cached, it will be reused.
  • If no token exists or it has expired, a new one will be fetched.

⚠️ Note: You usually don’t need to call this method directly when using TDK clients — use the hook-based pattern instead (see below).

Integrate with TDK Clients

To use the same AuthProvider across multiple clients (e.g. WalletsClient, IamClient), inject it into a shared HttpClient using TokenInjectingHandler (imported from AffinidiTdk.Common).

using AffinidiTdk.AuthProvider;
using AffinidiTdk.Common;
using AffinidiTdk.WalletsClient.Api;
using AffinidiTdk.WalletsClient.Client;

// init AuthProvider

var tokenHandler = new TokenInjectingHandler(
    () => authProvider.FetchProjectScopedTokenAsync(),
    new HttpClientHandler()
);

var httpClient = new HttpClient(tokenHandler);

// Share httpClient across multiple TDK clients
var walletApi = new WalletApi(httpClient, new Configuration());

See Examples and Tests

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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
1.1.1 176 10/1/2025