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
                    
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="Soenneker.Utils.Test.AuthHandler" Version="4.0.334" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.Test.AuthHandler" Version="4.0.334" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.Test.AuthHandler" />
                    
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 Soenneker.Utils.Test.AuthHandler --version 4.0.334
                    
#r "nuget: Soenneker.Utils.Test.AuthHandler, 4.0.334"
                    
#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 Soenneker.Utils.Test.AuthHandler@4.0.334
                    
#: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=Soenneker.Utils.Test.AuthHandler&version=4.0.334
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.Test.AuthHandler&version=4.0.334
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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 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 (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
Loading failed

Update dependency Soenneker.Utils.Jwt to 4.0.1478 (#885)