Duende.Labs.IdentityModel.DependencyInjection 2026.806.21

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

IdentityModel dependency injection for .NET

Dependency injection and IHttpClientFactory integration for Duende.Labs.IdentityModel.

Installation

dotnet add package Duende.Labs.IdentityModel.DependencyInjection

Note This package is experimental/preview.

What it does

Duende.Labs.IdentityModel is a dependency-free set of HttpClient extensions. Every request carries its own endpoint address and client credential. In an application those values are fixed per authority, so this package lets you configure them once:

services.AddIdentityModelClient(options =>
{
    options.Authority = new Uri("https://demo.duendesoftware.com");
    options.ClientCredential = new ClientCredential("m2m", "secret");
    options.Scope = "api";
});
public class Worker(IdentityModelClient client)
{
    public async Task RunAsync(CancellationToken ct)
    {
        var result = await client.RequestClientCredentialsTokenAsync(ct);
    }
}

Endpoints are resolved from the authority's discovery document, which is fetched once and reused for DiscoveryRefreshInterval (24 hours by default). Failed retrievals are never cached. If the authority or discovery policy changes, for example through a configuration reload, the cached document is discarded and re-fetched rather than served until the interval lapses.

Named clients

services.AddIdentityModelClient("customers", options => { /* ... */ });
services.AddIdentityModelClient("partners", options => { /* ... */ });

Resolve them with keyed services:

public class Worker([FromKeyedServices("customers")] IdentityModelClient client);

Adjusting individual requests

Each method takes an optional delegate that receives the request built from your configuration:

var result = await client.RequestClientCredentialsTokenAsync(
    ct,
    request => request with { Scope = "api.read" });

Composing handlers

Registration returns the IHttpClientBuilder for the backing client, so caching, resilience and telemetry compose as usual — and apply to discovery too:

services
    .AddIdentityModelClient(options => { /* ... */ })
    .AddHttpMessageHandler<MyHandler>()
    .AddStandardResilienceHandler();

Configuration binding

services.AddIdentityModelClient(builder.Configuration.GetSection("IdentityProvider"));

Recognised keys are Authority, ClientId, ClientSecret, ClientCredentialStyle, Scope, DiscoveryRefreshInterval, and the endpoint overrides. Relative endpoint overrides are resolved against Authority. Values are read explicitly rather than through reflection-based binding, so the package stays trim and AOT compatible.

Testing

There are no interfaces to mock. IdentityModelClient is a sealed concrete type; substitute an HttpMessageHandler instead:

services
    .AddIdentityModelClient(options => { /* ... */ })
    .ConfigurePrimaryHttpMessageHandler(() => new FakeHandler());

Scope

This package stops at endpoint resolution and configured defaults. Token caching, automatic refresh and DPoP nonce handling belong to Duende.AccessTokenManagement.

License

IdentityModel is open source under the Apache 2.0 license.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.806.21 92 8/6/2026
2026.804.20 95 8/4/2026
2026.729.19 108 7/29/2026