ArturRios.Jwt 1.0.0

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

Dotnet JWT

Provides a clean, minimal API for creating, validating and reading JSON Web Tokens (JWT) in .NET.

Requirements

  • .NET 10.0 or later

Installation

dotnet add package ArturRios.Jwt

Features

  • Create signed JWTs (HMAC-SHA256) from a JwtConfiguration
  • Validate a JWT's signature against a secret
  • Read the user id from a token's id claim
  • Validate a JwtConfiguration with FluentValidation rules before using it

Usage

Configuring

using ArturRios.Jwt;

var configuration = new JwtConfiguration(
    expirationInSeconds: 3600,
    issuer: "my-api",
    audience: "my-app",
    secret: "a-secret-key-that-is-at-least-32-bytes-long",
    claims: new Dictionary<string, string> { { "id", "42" } }
);

Validating the configuration

var validator = new JwtConfigurationValidator();
var result = validator.Validate(configuration);

if (!result.IsValid)
{
    // inspect result.Errors
}

Creating a token

var handler = new JwtHandler();
var token = handler.CreateToken(configuration);

Validating a token

var isValid = await handler.IsTokenValidAsync(token, configuration.Secret);

Reading the user id from a token

var userId = handler.GetUserIdFromToken(token);

Note: tokens are signed with HMAC-SHA256, which requires a secret of at least 32 bytes (256 bits).

Versioning

Semantic Versioning (SemVer). Breaking changes result in a new major version. New methods or non-breaking behavior changes increment the minor version; fixes or tweaks increment the patch.

Build, test and publish

Use the official .NET CLI to build, test and publish the project and Git for source control. If you want, optional helper toolsets I built to facilitate these tasks are available:

This project is licensed under the MIT License. A copy of the license is available at LICENSE in the repository.

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 ArturRios.Jwt:

Package Downloads
ArturRios.Util.WebApi

Utilities for developing web API's in .NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 152 7/2/2026