Tharga.Api
0.0.1-pre.3
This is a prerelease version of Tharga.Api.
dotnet add package Tharga.Api --version 0.0.1-pre.3
NuGet\Install-Package Tharga.Api -Version 0.0.1-pre.3
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="Tharga.Api" Version="0.0.1-pre.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tharga.Api" Version="0.0.1-pre.3" />
<PackageReference Include="Tharga.Api" />
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 Tharga.Api --version 0.0.1-pre.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tharga.Api, 0.0.1-pre.3"
#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 Tharga.Api@0.0.1-pre.3
#: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=Tharga.Api&version=0.0.1-pre.3&prerelease
#tool nuget:?package=Tharga.Api&version=0.0.1-pre.3&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Tharga Api
Reusable API-key authentication handler, controller registration, and OpenAPI/Swagger setup for ASP.NET Core projects. Targets .NET 9.0 and .NET 10.0.
Features
- API key authentication –
AuthenticationHandlerthat reads theX-API-KEYheader, validates it against a MongoDB-backed store, and populates claims (TeamKey,Name). - Controller registration –
AddThargaControllersregisters MVC controllers, OpenAPI document generation (with API key security scheme), Swagger UI, and endpoints API explorer in a single call. - API key management –
IApiKeyAdministrationServiceprovides key lookup, listing, refresh, and lock operations. A default MongoDB-backed implementation is included. - Pluggable storage – Implement
IApiKeyAdministrationServiceto use your own data store, or use the built-inApiKeyAdministrationServicewith Tharga.MongoDB.
Getting started
1. Install the package
dotnet add package Tharga.Api
2. Register controllers and authentication
// Program.cs
builder.Services.AddThargaControllers(o =>
{
o.SwaggerTitle = "My API v1";
});
builder.Services.AddAuthentication()
.AddThargaApiKeyAuthentication();
// If using the built-in MongoDB key store:
builder.Services.AddThargaApiKeys();
3. Map controllers and Swagger
var app = builder.Build();
app.UseThargaControllers();
app.UseAuthentication();
app.UseAuthorization();
app.Run();
4. Protect endpoints
[Authorize(Policy = ApiKeyConstants.PolicyName)]
[ApiController]
[Route("api/[controller]")]
public class MyController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
var teamKey = User.FindFirst(ApiKeyConstants.TeamKeyClaim)?.Value;
return Ok(new { teamKey });
}
}
5. Custom key service (optional)
To use your own storage backend, implement IApiKeyAdministrationService and register it:
builder.Services.AddAuthentication()
.AddThargaApiKeyAuthentication<MyCustomKeyService>();
Public API
| Type | Description |
|---|---|
IApiKey |
Interface representing an API key with metadata (Key, Name, ApiKey, TeamKey, Tags). |
IApiKeyAdministrationService |
Service interface for key lookup, listing, refresh, and lock. |
ApiKeyConstants |
Well-known constants: HeaderName, SchemeName, PolicyName, TeamKeyClaim. |
ApiKeyRegistration |
Extension methods: AddThargaApiKeyAuthentication, AddThargaApiKeyAuthentication<T>. |
ControllersRegistration |
Extension methods: AddThargaControllers, AddThargaApiKeys, UseThargaControllers. |
ThargaControllerOptions |
Options for Swagger title and route prefix. |
ApiKeyEntity |
Default MongoDB entity implementing IApiKey. |
IApiKeyRepository |
Repository interface for API key persistence. |
Dependencies
- Tharga.MongoDB – MongoDB repository infrastructure and auto-registration.
- Tharga.Toolkit – Shared utilities including API key hashing.
- Swashbuckle.AspNetCore – Swagger UI generation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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.
-
net10.0
- Microsoft.AspNetCore.OpenApi (>= 10.0.5)
- Swashbuckle.AspNetCore (>= 10.1.5)
- Tharga.MongoDB (>= 2.8.5-pre.19)
- Tharga.Toolkit (>= 1.15.18)
-
net9.0
- Microsoft.AspNetCore.OpenApi (>= 9.0.14)
- Swashbuckle.AspNetCore (>= 10.1.5)
- Tharga.MongoDB (>= 2.8.5-pre.19)
- Tharga.Toolkit (>= 1.15.18)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Tharga.Api:
| Package | Downloads |
|---|---|
|
Tharga.Blazor
Common features for blazor and radzen. Multitennant and more. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.0.1-pre.3 | 3 | 3/13/2026 |
| 0.0.1-pre.2 | 28 | 3/13/2026 |