ImanSoftware.Jwt 1.0.0

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

ImanSoftware.Jwt

Version: 1.0.0 | Last Updated: August 2026

A lightweight and extensible JWT authentication library for .NET with token generation, validation, and ASP.NET Core middleware support.

ImanSoftware.Jwt provides a clean abstraction over JWT operations, making it easy to generate, validate, and process JSON Web Tokens while integrating seamlessly with ASP.NET Core applications.


Installation

Install the package using the .NET CLI:

dotnet add package ImanSoftware.Jwt

Why ImanSoftware.Jwt?

Working directly with the JWT APIs often leads to duplicated configuration and authentication logic across projects.

Instead of scattering JWT-related code throughout your application, this package centralizes token generation, validation, and authentication into a single, reusable service.

Benefits include:

  • Simplified JWT management
  • Dependency Injection friendly
  • Clean Architecture compatible
  • Easy integration with ASP.NET Core
  • Lightweight and testable

Features

  • IJwtTokenService abstraction
  • ✅ JWT generation
  • ✅ JWT validation
  • ✅ Read claims from expired tokens
  • ✅ Configurable JwtOptions
  • ✅ ASP.NET Core authentication middleware
  • ✅ Dependency Injection support
  • ✅ Easy application setup

IJwtTokenService

The primary abstraction for working with JWT tokens.

Available methods:

  • GenerateToken()
  • ValidateToken()
  • GetPrincipalFromExpiredToken()

Example:

string token = _jwt.GenerateToken(claims);

bool isValid = _jwt.ValidateToken(token);

var principal = _jwt.GetPrincipalFromExpiredToken(token);

JwtTokenService

The default implementation is built on top of System.IdentityModel.Tokens.Jwt.

Features include:

  • Secure JWT generation
  • Token validation
  • Claims extraction
  • Expired token support (useful for refresh token scenarios)
  • Standards-compliant implementation

JwtOptions

JWT behavior is configured through the JwtOptions class.

Available settings:

Property Description
SecretKey Secret key used to sign tokens
Issuer Token issuer
Audience Token audience
ExpiryMinutes Token expiration time
ValidateLifetime Enables or disables lifetime validation

Example configuration:

{
  "Jwt": {
    "SecretKey": "your-secret-key",
    "Issuer": "MyApplication",
    "Audience": "MyApplication",
    "ExpiryMinutes": 60,
    "ValidateLifetime": true
  }
}

Dependency Injection

Register the JWT service using your application configuration.

var jwtOptions = builder.Configuration
    .GetSection("Jwt")
    .Get<JwtOptions>();

services.AddJwtTokenService(jwtOptions);

After registration, IJwtTokenService can be injected anywhere in your application.


JWT Middleware

The package includes a dedicated middleware that:

  • Reads the JWT from the Authorization header
  • Validates the token
  • Creates the authenticated ClaimsPrincipal
  • Assigns the user to HttpContext.User

Register the middleware in your request pipeline:

app.UseJwtAuthentication();

Example

using ImanSoftware.Jwt;

public class AuthService
{
    private readonly IJwtTokenService _jwt;

    public AuthService(IJwtTokenService jwt)
    {
        _jwt = jwt;
    }

    public string Login(string username, string password)
    {
        // Validate user credentials...

        var claims = new[]
        {
            new Claim(
                ClaimTypes.NameIdentifier,
                userId.ToString())
        };

        return _jwt.GenerateToken(claims);
    }
}

Complete Setup

var jwtOptions = builder.Configuration
    .GetSection("Jwt")
    .Get<JwtOptions>();

services.AddJwtTokenService(jwtOptions);

var app = builder.Build();

app.UseJwtAuthentication();

Common Use Cases

  • User authentication
  • API authorization
  • Refresh token workflows
  • Claims-based identity
  • Microservices authentication
  • Stateless security

Design Goals

  • Secure by default
  • Clean abstraction
  • Dependency Injection friendly
  • Lightweight
  • Easy configuration
  • ASP.NET Core integration
  • Standards compliant
  • Clean Architecture compatible
  • Easy to test

Requirements

  • .NET Standard 2.0+
  • .NET 6+
  • .NET 7+
  • .NET 8+
  • .NET 9+
  • .NET 10.0+

Author

Iman Estiri

📧 contact.imanestiri@gmail.com

📧 dev.imanestiri@gmail.com

GitHub:

https://github.com/ImanEstiri


License

This project is licensed 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 (1)

Showing the top 1 NuGet packages that depend on ImanSoftware.Jwt:

Package Downloads
ImanSoftware.Framework

Umbrella package that bundles all ImanSoftware modules for a unified development experience.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 159 8/3/2026