![]() |
VOOZH | about |
dotnet add package ControlR.ApiClient --version 0.24.14
NuGet\Install-Package ControlR.ApiClient -Version 0.24.14
<PackageReference Include="ControlR.ApiClient" Version="0.24.14" />
<PackageVersion Include="ControlR.ApiClient" Version="0.24.14" />Directory.Packages.props
<PackageReference Include="ControlR.ApiClient" />Project file
paket add ControlR.ApiClient --version 0.24.14
#r "nuget: ControlR.ApiClient, 0.24.14"
#:package ControlR.ApiClient@0.24.14
#addin nuget:?package=ControlR.ApiClient&version=0.24.14Install as a Cake Addin
#tool nuget:?package=ControlR.ApiClient&version=0.24.14Install as a Cake Tool
A .NET client library for interacting with the ControlR API. This library provides a strongly-typed interface for making API calls to the backend of a ControlR server.
IHttpClientFactorydotnet add package ControlR.ApiClient
The library supports two usage patterns: dependency injection (recommended for most applications) and a static builder pattern (useful for scripts or simple scenarios).
Configure the client in your Program.cs or startup file:
using ControlR.ApiClient;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddControlrApiClient(options =>
{
options.BaseUrl = new Uri("https://your-controlr-server.com");
options.PersonalAccessToken = "your-personal-access-token";
});
You can also load options from configuration using the overload that accepts IConfiguration:
using ControlR.ApiClient;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddControlrApiClient(
builder.Configuration,
ControlrApiClientOptions.SectionKey);
With the following configuration in appsettings.json:
{
"ControlrApiClient": {
"BaseUrl": "https://your-controlr-server.com",
"PersonalAccessToken": "your-personal-access-token"
}
}
Inject IControlrApi directly into your services:
using ControlR.ApiClient;
public class MyService
{
private readonly IControlrApi _client;
private readonly ILogger<MyService> _logger;
public MyService(IControlrApi client, ILogger<MyService> logger)
{
_client = client;
_logger = logger;
}
public async Task GetDevicesAsync(CancellationToken cancellationToken)
{
var devices = new List<DeviceResponseDto>();
await foreach (var device in _client.Devices.GetAllDevices(cancellationToken).WithCancellation(cancellationToken))
{
devices.Add(device);
}
_logger.LogInformation("Retrieved {DeviceCount} devices.", devices.Count);
foreach (var device in devices)
{
_logger.LogInformation(" - {DeviceName} (ID: {DeviceId})", device.Name, device.Id);
}
}
}
The static builder pattern is useful for console applications, scripts, or scenarios where you prefer not to use dependency injection.
Initialize the builder once at application startup:
using ControlR.ApiClient;
ControlrApiClientBuilder.Initialize(options =>
{
options.BaseUrl = new Uri("https://your-controlr-server.com");
options.PersonalAccessToken = "your-personal-access-token";
});
Get a client instance whenever needed:
var client = ControlrApiClientBuilder.GetClient();
var devices = new List<DeviceResponseDto>();
await foreach (var device in client.Devices.GetAllDevices(cancellationToken).WithCancellation(cancellationToken))
{
devices.Add(device);
}
Console.WriteLine($"Retrieved {devices.Count} devices.");
foreach (var device in devices)
{
Console.WriteLine($" - {device.Name} (ID: {device.Id})");
}
| Property | Type | Required | Description |
|---|---|---|---|
BaseUrl |
Uri |
Yes | The base URL of your ControlR server |
PersonalAccessToken |
string |
No | A personal access token for stateless auth (omit or leave null for interactive bearer auth) |
AuthenticationMethod |
ViewerAuthenticationMethod |
No | PersonalAccessToken (default) or InteractiveBearer |
The client supports two authentication modes:
Stateless — set PersonalAccessToken in options or call SetPersonalAccessToken() on the session. Works without any sign-in flow.
Stateful session backed by email/password sign-in. Resolve IControlrAuthSession to manage the session lifecycle:
var result = await authSession.SignIn(
new InteractiveSignInRequest
{
Email = "user@example.com",
Password = "password",
TwoFactorCode = twoFactorCode // only needed if 2FA is enabled for the account
});
if (result.Status == InteractiveLoginStatus.Authenticated)
{
// Session is ready. Tokens refresh automatically in the background.
}
For automatic re-auth across app restarts, cache the session snapshot and restore it:
// Persist after sign-in
var snapshot = authSession.GetAuthSnapshot();
// Store snapshot.BearerToken, snapshot.RefreshToken, snapshot.BearerTokenExpiresAt
// in a secure keychain.
// Restore on next launch
await authSession.RestoreAuthSnapshot(snapshot);
// Session resumes with the background refresh loop.
For two-factor or password-change flows, check RequiresTwoFactor and RequiresPasswordChange on IControlrAuthSession and re-call SignIn with the additional fields.
The ControlR API Client uses IHttpClientFactory under the hood to manage HttpClient instances. This provides several benefits:
This means you can safely create multiple client instances without worrying about common pitfalls associated with direct HttpClient usage.
For a complete working example, see the project in this repository.
This project is licensed under the .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on ControlR.ApiClient:
| Package | Downloads |
|---|---|
|
ControlR.Libraries.Viewer.Common
Common viewer utilities for ControlR, an open-source remote control and remote access solution. |
|
|
ControlR.Viewer.Avalonia
Open-source remote control and remote access. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.24.14 | 47 | 6/16/2026 |
| 0.23.17 | 469 | 6/2/2026 |
| 0.22.79 | 3,620 | 5/4/2026 |
| 0.21.59 | 977 | 4/7/2026 |
| 0.20.88 | 145 | 3/12/2026 |
| 0.20.87 | 143 | 3/12/2026 |
| 0.20.86 | 118 | 3/5/2026 |
| 0.20.85 | 117 | 3/4/2026 |
| 0.20.84-dev | 112 | 3/4/2026 |
| 0.20.82-dev | 113 | 3/4/2026 |
| 0.20.79-dev | 103 | 3/3/2026 |
| 0.19.2 | 409 | 1/27/2026 |
| 0.18.22 | 168 | 1/12/2026 |
| 0.17.20 | 159 | 12/31/2025 |
| 0.17.19-dev | 126 | 12/31/2025 |
| 0.17.17 | 139 | 12/31/2025 |