Afrisys.JwtAuthentication.AspNetCore 1.0.1

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

Afrisys.JwtAuthKit

A lightweight JWT authentication and API authorization library for ASP.NET Core.

Designed to simplify secure microservice communication using JWT Audience-based isolation, without complex policy or IdentityServer configuration.

NuGet Version NuGet Downloads


๐Ÿ“Œ Why This Exists

Modern microservice systems often struggle with:

  • Overly complex authentication configuration per service
  • Weak service-to-service isolation
  • Repeated JWT setup across APIs
  • Difficult-to-maintain authorization rules

Afrisys.JwtAuthKit solves this by enforcing a simple principle:

JWT Audience defines API access boundaries

Each API only accepts tokens explicitly intended for it.


โœจ Features

  • Minimal setup (single-line configuration)
  • Automatic JWT Audience validation
  • Works with any JWT provider (Duende, Auth0, Keycloak, Azure AD, etc.)
  • Lightweight with zero unnecessary dependencies
  • Compatible with Controllers and Minimal APIs
  • Clean separation of authentication and authorization logic

โšก Quick Start

1. Install Package

dotnet add package Afrisys.JwtAuthentication.AspNetCore

2. Configure appsettings.json

{
  "Auth": {
    "Authority": "http://your-identity-server.com",
    "Audience": "Your scope here"
  }
}

3. Register in Program.cs

using Afrisys.JwtAuthKit;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddJwtAuthKit(builder.Configuration);

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.Run();

4. Secure Your API

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class PlumbingController : ControllerBase
{
    [HttpGet]
    public IActionResult Get()
    {
        return Ok("Secure data accessed successfully.");
    }
}

๐Ÿ” How It Works

  1. Identity Provider issues a JWT token with an aud (audience) claim
  2. Each microservice defines its expected audience
  3. The library validates:
    • Token signature
    • Issuer (Authority)
    • Audience match
  4. If audience mismatch โ†’ request is rejected (401 Unauthorized)

๐Ÿงญ Audience Mapping Example

API Service Expected Audience
Plumbing API plumbing-api
Ecommerce API ecommerce-api
Notification Service notification-service

๐Ÿงช Example Token Request (Client Credentials)

curl --location 'https://your-identity-server.com/connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=plumbing-api' \
--data-urlencode 'client_secret=your-secret' \
--data-urlencode 'grant_type=client_credentials'

Response

{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}

๐Ÿ—๏ธ Architecture Overview

Client / Service
      โ†“
Identity Provider (JWT Issuance)
      โ†“
Afrisys.JwtAuthKit (Validation Layer)
      โ†“
Protected API Resource

โš™๏ธ Requirements

  • .NET 8 or later
  • ASP.NET Core Web API
  • Any JWT-compatible Identity Provider

๐Ÿ“„ License

MIT License


โค๏ธ Built For

Developers building secure, scalable, and clean microservice architectures.

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
1.0.1 103 4/26/2026
1.0.0 99 4/25/2026

Fixed JWT validation issue caused by dependency conflicts with Microsoft.IdentityModel packages.