Soenneker.Utils.Jwt
11.0.1549
Prefix Reserved
dotnet add package Soenneker.Utils.Jwt --version 11.0.1549
NuGet\Install-Package Soenneker.Utils.Jwt -Version 11.0.1549
<PackageReference Include="Soenneker.Utils.Jwt" Version="11.0.1549" />
<PackageVersion Include="Soenneker.Utils.Jwt" Version="11.0.1549" />
<PackageReference Include="Soenneker.Utils.Jwt" />
paket add Soenneker.Utils.Jwt --version 11.0.1549
#r "nuget: Soenneker.Utils.Jwt, 11.0.1549"
#:package Soenneker.Utils.Jwt@11.0.1549
#addin nuget:?package=Soenneker.Utils.Jwt&version=11.0.1549
#tool nuget:?package=Soenneker.Utils.Jwt&version=11.0.1549
Soenneker.Utils.Jwt
Creates and validates HS256 JWTs and validates Azure OpenID Connect tokens.
Installation
dotnet add package Soenneker.Utils.Jwt
Quick start
using Soenneker.Utils.Jwt.Registrars;
services.AddJwtUtilAsSingleton();
Then inject IJwtUtil wherever you need it.
Create and verify an HMAC token
Configure the default signing key and lifetime:
{
"Jwt": {
"SigningKey": "a-long-random-secret-kept-out-of-source-control",
"LifetimeMinutes": 30
}
}
string token = jwtUtil.Create(
subject: userId,
extraClaims: new Dictionary<string, object> { ["role"] = "admin" });
ClaimsPrincipal? principal = jwtUtil.Verify(token);
Create emits an HS256 token containing sub, jti, iat, nbf, and exp. Extra claim values
are converted to strings, and reserved claims supplied through extraClaims are ignored. You can
provide both signingKey and lifetime directly when configuration is unavailable.
Verify validates the signature and, by default, the expiration time with zero clock skew. It
does not validate issuer or audience, so use it only where possession of the shared key is the
intended trust boundary. Invalid or expired tokens return null.
Validate Azure OpenID Connect tokens
The Azure overloads require these configuration values:
{
"Azure": {
"AzureAd": {
"ClientId": "expected-audience",
"JwtIssuer": "https://login.microsoftonline.com/{tenant-id}/v2.0",
"MetadataAddress": "https://login.microsoftonline.com/{tenant-id}/v2.0/.well-known/openid-configuration"
}
}
}
ClaimsPrincipal? principal = await jwtUtil.GetPrincipal(token, cancellationToken: cancellationToken);
This path validates the configured issuer, audience, signature, expiration, and rotating signing
keys obtained from the HTTPS metadata endpoint. Invalid tokens return null; metadata retrieval
errors are logged and also result in null from GetPrincipal. Requested cancellation propagates.
Other validation option
GetValidationParameters(audience, issuer, publicKey, exponent) builds parameters for a specific
RSA public key. The modulus and exponent must be Base64Url encoded. It enables issuer, audience,
signature, and lifetime validation with zero clock skew.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.23.0)
- Soenneker.Extensions.Configuration (>= 11.0.917)
- Soenneker.Extensions.String (>= 11.0.820)
- Soenneker.Extensions.Task (>= 11.0.143)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Utils.Jwt:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.Test.AuthHandler
A custom test authentication handler that builds a ClaimsPrincipal from headers or a JWT to simulate authenticated users during integration tests. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.1549 | 181 | 11/11/2026 |
| 11.0.1548 | 66 | 11/11/2026 |
| 11.0.1547 | 111 | 11/11/2026 |
| 11.0.1546 | 133 | 11/11/2026 |
| 11.0.1545 | 70 | 11/11/2026 |
| 11.0.1544 | 162 | 11/11/2026 |
| 11.0.1543 | 85 | 11/10/2026 |
| 11.0.1542 | 676 | 11/3/2026 |
| 11.0.1541 | 154 | 11/3/2026 |
| 11.0.1540 | 169 | 11/2/2026 |
| 11.0.1539 | 298 | 10/27/2026 |
| 11.0.1538 | 186 | 10/26/2026 |
| 11.0.1537 | 181 | 10/26/2026 |
| 11.0.1535 | 95 | 10/26/2026 |
| 4.0.1534 | 163 | 10/25/2026 |
| 4.0.1533 | 751 | 10/15/2026 |
| 4.0.1532 | 102 | 10/14/2026 |
| 4.0.1531 | 145 | 10/14/2026 |
| 4.0.1528 | 240 | 10/14/2026 |
| 4.0.1522 | 239 | 10/13/2026 |
Updated Multiple NuGet packages