C# SDK
The PasskeyBase NuGet package provides an async C# client for the PasskeyBase Management API. Manage users, credentials, apps, roles, and enrollment tokens from your .NET backend.
Installation
Install via the .NET CLI:
Terminal
dotnet add package PasskeyBaseQuick Start
Initialize the client with your Management API key and tenant domain, then make your first API call.
Program.cs
using PasskeyBase;
var client = new PasskeyBaseClient(new PasskeyBaseOptions
{
ApiKey = "YOUR_MANAGEMENT_API_KEY",
Domain = "myapp.auth.ing",
});
// List all users
var users = await client.Users.ListAsync();
foreach (var user in users.Data)
{
Console.WriteLine($"{user.Id}: {user.DisplayName}");
}User Management
Create User
Create a user
var user = await client.Users.CreateAsync(new CreateUserParams
{
ExternalId = "user_123",
DisplayName = "Jane Doe",
});
Console.WriteLine($"Created user: {user.Id}");List Users
List users with pagination
// List with pagination
var users = await client.Users.ListAsync(new ListParams
{
Page = 1,
PerPage = 20,
});
foreach (var user in users.Data)
{
Console.WriteLine($"{user.Id}: {user.DisplayName}");
}
Console.WriteLine($"Total: {users.Pagination.Total}");Get User
Get a user by ID
var user = await client.Users.GetAsync("usr_abc123");
Console.WriteLine($"Name: {user.DisplayName}");
Console.WriteLine($"Passkeys: {user.PasskeyCount}");
Console.WriteLine($"Last login: {user.LastLoginAt}");Update User
Update a user
var user = await client.Users.UpdateAsync("usr_abc123", new UpdateUserParams
{
DisplayName = "Jane Smith",
});
Console.WriteLine($"Updated: {user.DisplayName}");Delete User
Deletes a user and all their associated passkeys.
Delete a user
await client.Users.DeleteAsync("usr_abc123");Block / Unblock User
Block and unblock
// Block a user (prevents authentication)
await client.Users.BlockAsync("usr_abc123");
// Unblock a user
await client.Users.UnblockAsync("usr_abc123");Credential Management
List Credentials
List all passkey credentials for a specific user.
List credentials
var credentials = await client.Credentials.ListAsync("usr_abc123");
foreach (var cred in credentials.Data)
{
Console.WriteLine($"{cred.Id}: {cred.DeviceName} ({cred.AuthenticatorType})");
}Delete Credential
Revoke a specific passkey credential.
Delete a credential
await client.Credentials.DeleteAsync("usr_abc123", "pk_xyz789");Client / App Management
Create App
Create an OAuth app
var app = await client.Apps.CreateAsync(new CreateAppParams
{
Name = "My Mobile App",
RedirectUris = new[] { "myapp://callback" },
});
Console.WriteLine($"Client ID: {app.Id}");Rotate Secret
Rotate client secret
var secret = await client.Apps.RotateSecretAsync("pk_live_abc123");
Console.WriteLine($"New secret: {secret.ClientSecret}");Role Management
Create Role
Create a role
var role = await client.Roles.CreateAsync(new CreateRoleParams
{
Name = "admin",
Description = "Administrator role",
});
Console.WriteLine($"Role ID: {role.Id}");Assign Users
Assign users to a role
await client.Roles.AssignUserAsync("role_abc123", "usr_abc123");
// List users in a role
var users = await client.Roles.ListUsersAsync("role_abc123");
foreach (var user in users.Data)
{
Console.WriteLine($"{user.Id}: {user.DisplayName}");
}Enrollment Tokens
Generate a one-time token for enrolling a passkey for an existing user. See the Enrollment guide for the full flow.
Create enrollment token
var token = await client.EnrollmentTokens.CreateAsync(new CreateEnrollmentTokenParams
{
ExternalId = "user_123",
DisplayName = "Jane Doe",
ExpiresIn = 3600,
});
Console.WriteLine($"Token: {token.Token}");
Console.WriteLine($"Expires: {token.ExpiresAt}");
// Return this token to your frontend for passkey enrollmentError Handling
API errors throw a PasskeyBaseExceptionwith structured error information.
Error handling
using PasskeyBase;
using PasskeyBase.Exceptions;
var client = new PasskeyBaseClient(new PasskeyBaseOptions
{
ApiKey = "YOUR_MANAGEMENT_API_KEY",
Domain = "myapp.auth.ing",
});
try
{
var user = await client.Users.GetAsync("usr_nonexistent");
}
catch (PasskeyBaseException e)
{
Console.WriteLine($"Error: {e.Error}"); // "not_found"
Console.WriteLine($"Message: {e.Message}"); // "User not found"
Console.WriteLine($"Status: {e.Status}"); // 404
}Configuration Options
Configuration
var client = new PasskeyBaseClient(new PasskeyBaseOptions
{
ApiKey = "YOUR_MANAGEMENT_API_KEY", // Required. Management API key.
Domain = "myapp.auth.ing", // Required. Your tenant domain.
Timeout = TimeSpan.FromSeconds(30), // Optional. Request timeout. Default: 10s.
MaxRetries = 3, // Optional. Max retry attempts. Default: 2.
BaseUrl = "https://custom.url", // Optional. Override API base URL.
});| Option | Type | Required | Description |
|---|---|---|---|
ApiKey | string | Yes | Your Management API key from the dashboard. |
Domain | string | Yes | Your tenant domain (e.g., myapp.auth.ing). |
Timeout | TimeSpan | No | Request timeout. Default: 10s. |
MaxRetries | int | No | Maximum retry attempts. Default: 2. |
BaseUrl | string | No | Override the API base URL. |