Ozcorps.Jwt 8.1.0

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

Ozcorps.Jwt

.NET 8.0 NuGet Version License: MIT

JWT (JSON Web Token) authentication library for ASP.NET Core. Provides Options Pattern configuration, Swagger integration, and a full-featured token service.

Installation

dotnet add package Ozcorps.Jwt
<PackageReference Include="Ozcorps.Jwt" Version="8.1.0" />

Configuration

Add the following section to appsettings.json:

{
  "Jwt": {
    "Issuer": "YourApp",
    "Audience": "YourApp.Users",
    "Key": "your-super-secret-key-at-least-32-chars-long",
    "ValidateIssuer": true,
    "ValidateAudience": true,
    "ValidateLifetime": true,
    "ValidateIssuerSigningKey": true,
    "ClockSkew": "00:00:00"
  }
}

Security: Never commit real JWT keys to source control. Use environment variables or a secrets manager.

Configuration Reference

Property Type Default Description
Issuer string Token issuer (required)
Audience string Token audience (required)
Key string HMAC-SHA256 signing key, min 32 characters (required)
ClockSkew TimeSpan 00:00:00 Clock skew tolerance for expiry validation
ValidateIssuer bool true Whether to validate the issuer claim
ValidateAudience bool true Whether to validate the audience claim
ValidateLifetime bool true Whether to validate token expiry
ValidateIssuerSigningKey bool true Whether to validate the signing key

Quick Start

using Ozcorps.Jwt.Extensions;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddJwtAuthentication(builder.Configuration);

var app = builder.Build();

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

app.Run();

Swagger Integration

builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
    options.AddJwtSecurity();
});

AddJwtSecurity() adds the Bearer security scheme to Swagger UI so tokens can be entered directly in the UI.

IJwtTokenService

IJwtTokenService is registered as scoped and available via dependency injection.

public class AuthController(IJwtTokenService jwtTokenService) : ControllerBase
{
    [HttpPost("login")]
    public IActionResult Login([FromBody] LoginRequest request)
    {
        // validate credentials...

        var token = jwtTokenService.GenerateToken(
            userId: user.Id.ToString(),
            username: user.Username,
            roles: new[] { "User" },
            expiration: DateTime.UtcNow.AddHours(8)
        );

        return Ok(new { token, expiresAt = jwtTokenService.GetTokenExpiration(token) });
    }
}

API

Method Description
GenerateToken(IEnumerable<Claim>, DateTime?) Generates a token from a custom claims list
GenerateToken(string userId, string username, IEnumerable<string>? roles, DateTime?) Generates a token for a user with optional roles
ValidateToken(string token) Validates a token and returns the ClaimsPrincipal, or null if invalid
GetTokenExpiration(string token) Returns the token's expiry time, or null if unreadable

Custom Section Name

// appsettings.json
{
  "Auth": {
    "Jwt": { "Issuer": "...", "Audience": "...", "Key": "..." }
  }
}

// Program.cs
builder.Services.AddJwtAuthentication(builder.Configuration, sectionName: "Auth:Jwt");
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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 was computed.  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
8.1.0 83 3/11/2026
8.0.0 211 9/3/2025