Making.Jwt 1.0.9-preview

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

Making.Jwt

JWT authentication and authorization support for the Making framework.

Overview

Making.Jwt provides comprehensive JWT (JSON Web Token) authentication and authorization functionality for the Making framework. It includes token generation, validation, refresh token management, and ASP.NET Core integration.

Features

  • JWT Token Generation: Create secure JWT tokens with custom claims
  • Token Validation: Comprehensive token validation with security checks
  • Refresh Token Support: Secure refresh token implementation with storage abstraction
  • Claims Management: Easy claims handling and extraction
  • ASP.NET Core Integration: Middleware and authentication handlers
  • Configurable Options: Flexible JWT configuration options

Installation

dotnet add package Making.Jwt

Usage

Configuration

{
  "Jwt": {
    "Issuer": "https://your-app.com",
    "Audience": "https://your-app.com",
    "SecretKey": "your-super-secret-key-here-must-be-at-least-32-characters",
    "ExpirationMinutes": 60,
    "RefreshTokenExpirationDays": 7,
    "ValidateIssuer": true,
    "ValidateAudience": true,
    "ValidateLifetime": true,
    "ValidateIssuerSigningKey": true
  }
}

Register Services

services.AddMakingJwt(configuration);

Generate JWT Tokens

public class AuthService
{
    private readonly IJwtService _jwtService;
    
    public AuthService(IJwtService jwtService)
    {
        _jwtService = jwtService;
    }
    
    public async Task<TokenResult> LoginAsync(string username, string password)
    {
        // Validate user credentials...
        
        var claims = new JwtClaims
        {
            UserId = user.Id,
            UserName = user.UserName,
            Email = user.Email,
            Roles = user.Roles.ToArray()
        };
        
        return await _jwtService.GenerateTokenAsync(claims);
    }
}

Validate Tokens

public class TokenController : ControllerBase
{
    private readonly IJwtService _jwtService;
    
    public TokenController(IJwtService jwtService)
    {
        _jwtService = jwtService;
    }
    
    [HttpPost("validate")]
    public async Task<IActionResult> ValidateToken([FromBody] string token)
    {
        var result = await _jwtService.ValidateTokenAsync(token);
        
        if (result.IsValid)
        {
            return Ok(new { Valid = true, Claims = result.Claims });
        }
        
        return BadRequest(new { Valid = false, Error = result.Error });
    }
}

Refresh Tokens

[HttpPost("refresh")]
public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenRequest request)
{
    var result = await _jwtService.RefreshTokenAsync(request.RefreshToken);
    
    if (result.IsValid)
    {
        return Ok(result.TokenResult);
    }
    
    return BadRequest(new { Error = result.Error });
}

Custom Refresh Token Store

public class DatabaseRefreshTokenStore : IRefreshTokenStore
{
    private readonly IDbContext _context;
    
    public DatabaseRefreshTokenStore(IDbContext context)
    {
        _context = context;
    }
    
    public async Task StoreAsync(string refreshToken, string userId, DateTime expirationTime)
    {
        var tokenEntity = new RefreshToken
        {
            Token = refreshToken,
            UserId = userId,
            ExpirationTime = expirationTime,
            CreatedAt = DateTime.UtcNow
        };
        
        _context.RefreshTokens.Add(tokenEntity);
        await _context.SaveChangesAsync();
    }
    
    public async Task<bool> ValidateAsync(string refreshToken)
    {
        var token = await _context.RefreshTokens
            .FirstOrDefaultAsync(t => t.Token == refreshToken);
        
        return token != null && token.ExpirationTime > DateTime.UtcNow;
    }
    
    public async Task RevokeAsync(string refreshToken)
    {
        var token = await _context.RefreshTokens
            .FirstOrDefaultAsync(t => t.Token == refreshToken);
        
        if (token != null)
        {
            _context.RefreshTokens.Remove(token);
            await _context.SaveChangesAsync();
        }
    }
}

// Register custom store
services.AddScoped<IRefreshTokenStore, DatabaseRefreshTokenStore>();

Requirements

  • .NET Standard 2.0+
  • System.IdentityModel.Tokens.Jwt
  • Microsoft.AspNetCore.Authentication.JwtBearer
  • Microsoft.AspNetCore.Http.Abstractions
  • Microsoft.Extensions.Configuration.Abstractions
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • Microsoft.Extensions.Options
  • Microsoft.Extensions.Logging.Abstractions
  • Microsoft.Extensions.Hosting.Abstractions
  • Making.Security

License

This project is part of the Making framework.

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

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.9-preview 111 8/20/2025
1.0.8-preview 110 8/20/2025
1.0.6-preview 115 8/19/2025
1.0.4-preview 113 8/10/2025
1.0.1-preview 425 7/25/2025
1.0.0-preview 403 7/25/2025