Mugi.Jwt 0.1.3

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

Mugi.Jwt

Mugi.Jwt signs and verifies compact JWTs for the Mugi web framework without reflection, so it works under NativeAOT. It supports HS256, RS256, and ES256, and ships an authentication middleware.

Sign and verify

using Mugi.Jwt;

var key = JwtKey.HS256("01234567890123456789012345678901"u8);
var token = Jwt.Sign(
    new JwtPayload
    {
        Subject = "alice",
        ExpiresAt = DateTimeOffset.UtcNow.AddMinutes(5)
    },
    key);

var result = Jwt.Verify(token, key);
if (result.IsValid)
{
    Console.WriteLine(result.Payload!.Subject);
}

Jwt.Verify checks the signature and registered claims, then returns a JwtResult rather than throwing for an invalid token. Verification fixes the accepted algorithm to the supplied key: it rejects none, unknown algorithms, and tokens whose algorithm does not match the key before signature validation.

JwtKey.HS256 copies a secret of at least 32 bytes, JwtKey.RS256 accepts an RSA key of at least 2048 bits, and JwtKey.ES256 accepts an ECDSA key on NIST P-256. JwtPayload carries the registered claims and adds scalar string, integer, and Boolean claims with WithClaim. JwtValidation can require an exact Issuer, require an Audience, set ClockSkew, control RequireExpiration, and supply a Clock.

Middleware

JwtAuth.Middleware validates a bearer token before calling the next handler. Missing or invalid tokens return 401 with a Bearer challenge. The generic overload stores the verified payload on a typed context:

using Mugi;
using Mugi.Jwt;

public sealed class ApiContext : Context, IJwtContext
{
    public JwtPayload? Jwt { get; set; }
}

var api = new App<ApiContext>();
api.Use(JwtAuth.Middleware<ApiContext>(new JwtAuthOptions { Key = key }));

Full documentation is at github.com/hckaye/Mugi.

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 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
0.1.3 106 8/28/2026
0.1.2 92 8/28/2026