PasarGuard.ApiClient 5.4.1.1

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

PasarGuard.ApiClient

NuGet NuGet downloads CI License: MIT

PasarGuard.ApiClient is a strongly typed, asynchronous .NET client for PasarGuardAPI. It provides dependency-injection integration, bearer-token authentication, typed request and response models, structured error handling, response headers, and cancellation support across the complete PasarGuardAPI 5.4.1 surface.

Requirements

  • .NET 10 or later
  • A PasarGuardAPI 5.4.1 instance

Installation

Install the package from NuGet.org:

dotnet add package PasarGuard.ApiClient

Or add it directly to your project:

<PackageReference Include="PasarGuard.ApiClient" Version="5.4.1.1" />

Configuration

Add the client settings to appsettings.json:

{
  "PasarGuardClient": {
    "BaseUrl": "https://pasarguard.example:8000",
    "TimeoutSeconds": 100,
    "BearerToken": "",
    "AuthorizationScheme": "Bearer"
  }
}

Register the client with the application configuration:

using PasarGuard.ApiClient.DependencyInjection;

builder.Services.AddPasarGuardApiClient(builder.Configuration);

Configuration can also be supplied directly:

builder.Services.AddPasarGuardApiClient(options =>
{
    options.BaseUrl = "https://pasarguard.example:8000";
    options.TimeoutSeconds = 100;
    options.BearerToken = accessToken;
});

Authentication

Resolve the aggregate client and shared token provider:

using PasarGuard.ApiClient.Abstractions;
using PasarGuard.ApiClient.Authentication;

var client = serviceProvider.GetRequiredService<IPasarGuardApiClient>();
var tokenProvider = serviceProvider.GetRequiredService<MutableAccessTokenProvider>();

Obtain an admin token and apply it to subsequent requests:

using PasarGuard.ApiClient.Models;

var tokenResult = await client.Admin.AdminTokenAsync(new BodyAdminToken
{
    Username = username,
    Password = password
});

if (!tokenResult.IsSuccess || tokenResult.Value is null)
{
    throw new InvalidOperationException(tokenResult.Error?.Message);
}

tokenProvider.SetToken(tokenResult.Value.AccessToken);

For applications that already manage credentials, register a custom IAccessTokenProvider before calling AddPasarGuardApiClient.

Usage

All operations are asynchronous and return ApiResult or ApiResult<T>.

var result = await client.User.GetUsersAsync(limit: 20, cancellationToken: cancellationToken);

if (result.IsSuccess)
{
    foreach (var user in result.Value?.Users ?? [])
    {
        Console.WriteLine(user.Username);
    }
}
else
{
    Console.WriteLine($"Request failed with status {(int)result.StatusCode}: {result.Error?.Message}");
}

Create an API key:

var result = await client.ApiKeys.CreateApiKeyAsync(new APIKeyCreate
{
    Name = "automation",
    InheritPermissions = true
}, cancellationToken);

Read response headers:

var result = await client.Subscription.UserSubscriptionHeadersAsync(
    token,
    cancellationToken: cancellationToken);

if (result.Headers.TryGetValue("subscription-userinfo", out var values))
{
    Console.WriteLine(values[0]);
}

Each result exposes:

  • IsSuccess for success detection
  • StatusCode for the HTTP status
  • Value for typed response data
  • Error for HTTP, transport, and serialization failures
  • Headers for response and content headers

API areas

The aggregate IPasarGuardApiClient provides access to the following clients:

Property Area
Admin Admin authentication and management
AdminRoles Admin roles and permissions
ApiKeys API key lifecycle
ClientTemplate Client templates
Core Core configurations and Reality scanning
Default Root and health endpoints
Groups User groups
Host Hosts
Node Nodes, status, latency, and metrics
Settings Server settings
Setup Owner setup and upgrade
Subscription Subscription output and headers
System System, resource, and WireGuard statistics
User Users and bulk operations
UserHwid User HWID management
UserTemplate User templates

Individual clients such as IUserClient or INodeClient can also be resolved directly through dependency injection.

Compatibility

Each package release identifies its supported PasarGuardAPI version. Applications should keep the client and server versions aligned when endpoint contracts or data models change.

Versioning

Package versions use the format PasarGuardAPI version.Package revision. For example, 5.4.1.1 targets PasarGuardAPI 5.4.1 and represents the first client-package revision for that API release. Package-only fixes increment the fourth segment, while support for a new PasarGuardAPI release updates the first three segments and resets the package revision to 1.

License

PasarGuard.ApiClient is available 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

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
5.4.1.1 96 9/12/2026
5.3.0.1 114 9/2/2026
5.2.1.1 105 8/14/2026
5.2.1 110 8/14/2026