Aspire.Keycloak.Authentication 17.0.0-preview.1.26567.5

Prefix Reserved
This is a prerelease version of Aspire.Keycloak.Authentication.
dotnet add package Aspire.Keycloak.Authentication --version 17.0.0-preview.1.26567.5
                    
NuGet\Install-Package Aspire.Keycloak.Authentication -Version 17.0.0-preview.1.26567.5
                    
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="Aspire.Keycloak.Authentication" Version="17.0.0-preview.1.26567.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aspire.Keycloak.Authentication" Version="17.0.0-preview.1.26567.5" />
                    
Directory.Packages.props
<PackageReference Include="Aspire.Keycloak.Authentication" />
                    
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 Aspire.Keycloak.Authentication --version 17.0.0-preview.1.26567.5
                    
#r "nuget: Aspire.Keycloak.Authentication, 17.0.0-preview.1.26567.5"
                    
#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 Aspire.Keycloak.Authentication@17.0.0-preview.1.26567.5
                    
#: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=Aspire.Keycloak.Authentication&version=17.0.0-preview.1.26567.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Aspire.Keycloak.Authentication&version=17.0.0-preview.1.26567.5&prerelease
                    
Install as a Cake Tool

Aspire.Keycloak.Authentication library

Adds JwtBearer and OpenId Connect authentication to the project via a Keycloak.

Getting started

Prerequisites

  • A Keycloak server instance
  • A Keycloak realm
  • For JwtBearer authentication, a configured audience in the Keycloak realm
  • For OpenId Connect authentication, the ID of a client configured in the Keycloak realm

Install the package

Install the Aspire Keycloak library with NuGet:

dotnet add package Aspire.Keycloak.Authentication

Jwt bearer authentication usage example

In the Program.cs file of your ASP.NET Core API project, call the AddKeycloakJwtBearer extension method to add JwtBearer authentication, using a connection name, realm and any required JWT Bearer options:

builder.Services.AddAuthentication()
                .AddKeycloakJwtBearer("keycloak", realm: "WeatherShop", options =>
                {
                    options.Audience = "weather.api";
                });

You can set many other options via the Action<JwtBearerOptions> configureOptions delegate.

OpenId Connect authentication usage example

In the Program.cs file of your Blazor project, call the AddKeycloakOpenIdConnect extension method to add OpenId Connect authentication, using a connection name, realm and any required OpenId Connect options:

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
                .AddKeycloakOpenIdConnect(
                    "keycloak", 
                    realm: "WeatherShop", 
                    options =>
                    {
                        options.ClientId = "WeatherWeb";
                        options.ResponseType = OpenIdConnectResponseType.Code;
                        options.Scope.Add("weather:all");
                    });

You can set many other options via the Action<OpenIdConnectOptions>? configureOptions delegate.

AppHost extensions

In your AppHost project, install the Aspire.Hosting.Keycloak library with NuGet:

dotnet add package Aspire.Hosting.Keycloak
dotnet add package Aspire.Hosting.Dotnet

Then, in the AppHost.cs file of AppHost, register a Keycloak server and consume the connection using the following methods:

var keycloak = builder.AddKeycloak("keycloak", 8080);

var apiService = builder.AddDotnetProject("apiservice", "../Keycloak.ApiService/Keycloak.ApiService.csproj")
                        .WithReference(keycloak);

builder.AddDotnetProject("webfrontend", "../Keycloak.Web/Keycloak.Web.csproj")
       .WithExternalHttpEndpoints()
       .WithReference(keycloak)
       .WithReference(apiService);

Recommendation: For local development use a stable port for the Keycloak resource (8080 in the example above). It can be any port, but it should be stable to avoid issues with browser cookies that will persist OIDC tokens (which include the authority URL, with port) beyond the lifetime of the AppHost.

The WithReference method configures a connection in the Keycloak.ApiService and Keycloak.Web projects named keycloak.

In the Program.cs file of Keycloak.ApiService, the Keycloak connection can be consumed using:

builder.Services.AddAuthentication()
                .AddKeycloakJwtBearer("keycloak", realm: "WeatherShop");

And in the Program.cs file of Keycloak.Web, the Keycloak connection can be consumed using:

var oidcScheme = OpenIdConnectDefaults.AuthenticationScheme;

builder.Services.AddAuthentication(oidcScheme)
                .AddKeycloakOpenIdConnect(
                    "keycloak", 
                    realm: "WeatherShop", 
                    oidcScheme);

Additional documentation

Feedback & contributing

https://github.com/microsoft/aspire

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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Aspire.Keycloak.Authentication:

Package Downloads
Lewee.Infrastructure.Keycloak

Package Description

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Aspire.Keycloak.Authentication:

Repository Stars
CommunityToolkit/Aspire
A community project with additional components and extensions for Aspire
foxminchan/BookWorm
Reference architecture for building agentic applications with Aspire microservices and micro frontends, integrating MCP, A2A, AG-UI, and A2UI
baotoq/micro-commerce
.NET 10 .NET Aspire
Version Downloads Last Updated
17.0.0-preview.1.26567.5 1,816 11/18/2026
13.6.5-preview.1.26559.7 13,366 11/10/2026
13.6.4-preview.1.26523.11 12,344 10/24/2026
13.6.3-preview.1.26521.2 12,596 10/21/2026
13.6.2-preview.1.26519.11 1,081 10/20/2026
13.6.1-preview.1.26506.6 14,739 10/7/2026
13.6.0-preview.1.26479.8 10,060 9/29/2026
13.5.4-preview.1.26464.4 15,186 9/15/2026
13.5.3-preview.1.26425.3 16,154 8/25/2026
13.5.2-preview.1.26421.6 2,251 8/21/2026
13.5.1-preview.1.26420.4 10,875 8/20/2026
13.5.0-preview.1.26417.10 6,815 8/18/2026
13.4.6-preview.1.26319.6 61,432 6/19/2026
13.4.5-preview.1.26316.12 2,875 6/17/2026
13.4.4-preview.1.26314.3 2,795 6/15/2026
13.4.3-preview.1.26305.13 4,882 6/8/2026
13.4.2-preview.1.26303.6 3,614 6/3/2026
13.4.1-preview.1.26303.3 104 6/3/2026
13.4.0-preview.1.26281.18 14,815 6/1/2026
13.3.5-preview.1.26270.6 11,699 5/21/2026
Loading failed