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" />
                    
Directory.Packages.props
<PackageReference Include="Tharga.Api" />
                    
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 Tharga.Api --version 0.0.1-pre.3
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Tharga.Api&version=0.0.1-pre.3&prerelease
                    
Install as a Cake Tool

Tharga Api

NuGet Nuget License GitHub repo Issues

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 authenticationAuthenticationHandler that reads the X-API-KEY header, validates it against a MongoDB-backed store, and populates claims (TeamKey, Name).
  • Controller registrationAddThargaControllers registers MVC controllers, OpenAPI document generation (with API key security scheme), Swagger UI, and endpoints API explorer in a single call.
  • API key managementIApiKeyAdministrationService provides key lookup, listing, refresh, and lock operations. A default MongoDB-backed implementation is included.
  • Pluggable storage – Implement IApiKeyAdministrationService to use your own data store, or use the built-in ApiKeyAdministrationService with 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

Product 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.

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