ControlR.ApiClient 0.23.17

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

ControlR API Client

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.

Features

  • Strongly-typed API client generated from OpenAPI specification
  • Built-in support for dependency injection
  • Static builder pattern for scenarios where dependency injection is not available
  • Efficient HTTP connection management via IHttpClientFactory
  • Automatic request/response serialization
  • Two authentication modes: Personal Access Token (stateless) and Interactive Bearer (email/password with automatic token refresh)
  • Interactive bearer session supports two-factor authentication and password-change flows
  • Session snapshot/restore for persisting tokens (e.g., caching in a secure keychain for automatic re-auth across app restarts)

Installation

dotnet add package ControlR.ApiClient

Quick Start

The library supports two usage patterns: dependency injection (recommended for most applications) and a static builder pattern (useful for scripts or simple scenarios).

Option 1: Dependency Injection

Service Registration

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"
  }
}
Using the Client

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);
        }
    }
}

Option 2: Static Builder

The static builder pattern is useful for console applications, scripts, or scenarios where you prefer not to use dependency injection.

Initialization

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";
});
Using the Client

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})");
}

Configuration

ControlrApiClientOptions

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

Authentication

The client supports two authentication modes:

Personal Access Token (PAT)

Stateless — set PersonalAccessToken in options or call SetPersonalAccessToken() on the session. Works without any sign-in flow.

Interactive Bearer

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.

Obtaining a Personal Access Token

  1. Log in to your ControlR server
  2. Navigate to your account settings
  3. Generate a new Personal Access Token
  4. Store it securely (e.g., using User Secrets in development or secure configuration in production)

How It Works

IHttpClientFactory Integration

The ControlR API Client uses IHttpClientFactory under the hood to manage HttpClient instances. This provides several benefits:

  • Prevents socket exhaustion: Automatically manages the lifecycle of HTTP connections
  • Handles DNS changes: Respects DNS TTL by periodically recycling connections
  • Efficient resource usage: Pools and reuses connections
  • Handler pipeline: Supports middleware-style message handlers for cross-cutting concerns

This means you can safely create multiple client instances without worrying about common pitfalls associated with direct HttpClient usage.

Example Project

For a complete working example, see the ControlR.ApiClientExample project in this repository.

License

This project is licensed under the MIT License.

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 (2)

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.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.23.17 0 6/2/2026
0.22.79 2,373 5/4/2026
0.21.59 972 4/7/2026
0.20.88 142 3/12/2026
0.20.87 137 3/12/2026
0.20.86 113 3/5/2026
0.20.85 112 3/4/2026
0.20.84-dev 106 3/4/2026
0.20.82-dev 107 3/4/2026
0.20.79-dev 99 3/3/2026
0.19.2 363 1/27/2026
0.18.22 164 1/12/2026
0.17.20 158 12/31/2025
0.17.19-dev 126 12/31/2025
0.17.17 133 12/31/2025