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
<PackageReference Include="PasarGuard.ApiClient" Version="5.4.1.1" />
<PackageVersion Include="PasarGuard.ApiClient" Version="5.4.1.1" />
<PackageReference Include="PasarGuard.ApiClient" />
paket add PasarGuard.ApiClient --version 5.4.1.1
#r "nuget: PasarGuard.ApiClient, 5.4.1.1"
#:package PasarGuard.ApiClient@5.4.1.1
#addin nuget:?package=PasarGuard.ApiClient&version=5.4.1.1
#tool nuget:?package=PasarGuard.ApiClient&version=5.4.1.1
PasarGuard.ApiClient
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.1instance
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:
IsSuccessfor success detectionStatusCodefor the HTTP statusValuefor typed response dataErrorfor HTTP, transport, and serialization failuresHeadersfor 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 | Versions 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. |
-
net10.0
- Microsoft.Extensions.Http (>= 10.0.12)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.