Internal module for managing access tokens
$ dotnet add package AffinidiTdk.AuthProviderThis is a .NET TDK package which generates authorisation tokens to initialise TDK clients to access Affinidi services.
8.0.400)You can check your installed version using:
dotnet --version
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:
The AuthProvider class is thread-safe and designed for high-concurrency environments:
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();
⚠️ Note: You usually don’t need to call this method directly when using TDK clients — use the hook-based pattern instead (see below).
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());