Soenneker.Utils.Test.AuthHandler
4.0.334
Prefix Reserved
dotnet add package Soenneker.Utils.Test.AuthHandler --version 4.0.334
NuGet\Install-Package Soenneker.Utils.Test.AuthHandler -Version 4.0.334
<PackageReference Include="Soenneker.Utils.Test.AuthHandler" Version="4.0.334" />
<PackageVersion Include="Soenneker.Utils.Test.AuthHandler" Version="4.0.334" />
<PackageReference Include="Soenneker.Utils.Test.AuthHandler" />
paket add Soenneker.Utils.Test.AuthHandler --version 4.0.334
#r "nuget: Soenneker.Utils.Test.AuthHandler, 4.0.334"
#:package Soenneker.Utils.Test.AuthHandler@4.0.334
#addin nuget:?package=Soenneker.Utils.Test.AuthHandler&version=4.0.334
#tool nuget:?package=Soenneker.Utils.Test.AuthHandler&version=4.0.334
Soenneker.Utils.Test.AuthHandler
A test authentication handler for integration tests. It creates an authenticated user from simple request headers or an existing bearer token.
Installation
dotnet add package Soenneker.Utils.Test.AuthHandler
Setup
using Microsoft.AspNetCore.Authentication;
using Soenneker.Utils.Test.AuthHandler;
services
.AddAuthentication("Test")
.AddScheme<AuthenticationSchemeOptions, TestAuthHandler>("Test", _ => { });
TestAuthHandler depends on IJwtUtil, so register that in the test host as well. Set "Test" as the default authentication scheme when requests should use this handler automatically.
Authenticate a test request
The simplest option is to send a user ID. Email and roles are optional:
client.DefaultRequestHeaders.Add("AuthorizationUserId", "test-user-123");
client.DefaultRequestHeaders.Add("AuthorizationEmail", "test@example.com");
client.DefaultRequestHeaders.Add("AuthorizationRoles", "Admin,Manager");
The resulting principal contains the Microsoft identity-platform object identifier claim, an optional ClaimTypes.Email claim, and one ClaimTypes.Role claim per role. Role values may be sent as repeated headers, comma-separated values, or both; whitespace around comma-separated roles is trimmed. If AuthorizationRoles is omitted, the handler assigns the Admin role.
AuthorizationUserId takes precedence over Authorization. Header-created identities use the configured authentication scheme name.
Authenticate with a token
Alternatively, send an authorization value containing a scheme followed by a token:
using System.Net.Http.Headers;
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token);
The handler passes the text after the first space to IJwtUtil.GetPrincipal. For test compatibility it does not require the scheme text itself to be Bearer. If the token does not produce a principal, authentication fails instead of creating a ticket.
Failure behavior
Authentication fails when neither AuthorizationUserId nor Authorization is present. JWT parsing exceptions from IJwtUtil propagate through the authentication pipeline; a null principal becomes a normal failed authentication result.
This package is intended only for controlled integration-test hosts. The identity headers are trusted input and must never be enabled as an authentication mechanism in a deployed application.
| Product | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.11)
- Soenneker.Extensions.List.Claims (>= 4.0.55)
- Soenneker.Utils.Jwt (>= 4.0.1478)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Soenneker.Utils.Test.AuthHandler:
| Package | Downloads |
|---|---|
|
Soenneker.Fixtures.Integration
Provides a reusable and generic integration test xunit fixture that dynamically registers and configures WebApplicationFactory instances for multiple ASP.NET Core projects with support for custom app settings, authentication, logging, and test utilities. |
|
|
Soenneker.TestHosts.Integration
Provides a reusable and generic integration test host that dynamically registers and configures WebApplicationFactory instances for multiple ASP.NET Core projects with support for custom app settings, authentication, logging, and test utilities. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.334 | 0 | 8/31/2026 |
| 4.0.333 | 0 | 8/30/2026 |
| 4.0.332 | 0 | 8/30/2026 |
| 4.0.331 | 10 | 8/30/2026 |
| 4.0.330 | 47 | 8/30/2026 |
| 4.0.329 | 39 | 8/30/2026 |
| 4.0.328 | 37 | 8/29/2026 |
| 4.0.327 | 41 | 8/29/2026 |
| 4.0.326 | 86 | 8/29/2026 |
| 4.0.325 | 228 | 8/26/2026 |
| 4.0.324 | 95 | 8/26/2026 |
| 4.0.323 | 86 | 8/26/2026 |
| 4.0.322 | 146 | 8/25/2026 |
| 4.0.321 | 208 | 8/21/2026 |
| 4.0.320 | 313 | 8/18/2026 |
| 4.0.319 | 314 | 8/12/2026 |
| 4.0.318 | 134 | 8/11/2026 |
| 4.0.317 | 305 | 8/8/2026 |
| 4.0.316 | 193 | 8/7/2026 |
| 4.0.315 | 242 | 7/29/2026 |
Update dependency Soenneker.Utils.Jwt to 4.0.1478 (#885)