Soenneker.Utils.Test.AuthHandler 11.0.400

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Utils.Test.AuthHandler --version 11.0.400
                    
NuGet\Install-Package Soenneker.Utils.Test.AuthHandler -Version 11.0.400
                    
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="11.0.400" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.Test.AuthHandler" Version="11.0.400" />
                    
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 11.0.400
                    
#r "nuget: Soenneker.Utils.Test.AuthHandler, 11.0.400"
                    
#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@11.0.400
                    
#: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=11.0.400
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.Test.AuthHandler&version=11.0.400
                    
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 net11.0 is compatible. 
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
11.0.408 181 11/18/2026
11.0.407 125 11/18/2026
11.0.403 334 11/15/2026
11.0.402 231 11/11/2026
11.0.401 110 11/11/2026
11.0.400 146 11/11/2026
11.0.399 152 11/11/2026
11.0.398 105 11/11/2026
11.0.397 119 11/11/2026
11.0.396 130 11/11/2026
11.0.395 210 11/11/2026
11.0.394 331 11/3/2026
11.0.393 138 11/3/2026
11.0.392 168 11/2/2026
11.0.391 254 10/27/2026
11.0.390 177 10/26/2026
11.0.389 180 10/26/2026
11.0.388 135 10/26/2026
11.0.387 109 10/26/2026
4.0.386 515 10/15/2026
Loading failed

Updated Multiple NuGet packages