Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0df225d
**Add Keycloak with Postgres integration**
max2020204 Aug 26, 2025
2e07fa8
Refactor Keycloak Postgres extension for improved configuration
max2020204 Aug 26, 2025
1bf7ea7
Merge branch 'main' into KeycloakPostgres
max2020204 Aug 26, 2025
90621f4
Refactor Keycloak Postgres extension for streamlined configuration
max2020204 Aug 26, 2025
7a4fc17
Update src/CommunityToolkit.Aspire.Keycloak.Postgress/KeycloakPostgre…
max2020204 Aug 27, 2025
9b11f66
Refactor Keycloak Postgres extension and restructure project
max2020204 Aug 27, 2025
03cbc0a
Merge branch 'main' into KeycloakPostgres
max2020204 Aug 27, 2025
53c7ca1
Update src/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres/Keycl…
max2020204 Aug 28, 2025
9c913c5
Update src/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres/Keycl…
max2020204 Aug 28, 2025
d77acaf
Update src/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres/Keycl…
max2020204 Aug 28, 2025
fcfad00
Merge remote-tracking branch 'origin/main' into KeycloakPostgres
max2020204 Aug 28, 2025
6cd7d93
Merge branch 'main' into KeycloakPostgres
max2020204 Aug 28, 2025
d4720a9
Remove Postgres-specific Keycloak extension and merge functionality i…
max2020204 Aug 28, 2025
3962aa1
Merge remote-tracking branch 'origin/KeycloakPostgres' into KeycloakP…
max2020204 Aug 28, 2025
beb9fe9
Merge branch 'main' into KeycloakPostgres
max2020204 Aug 29, 2025
e01ce34
Update tests/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres.Tes…
max2020204 Aug 29, 2025
19c6f9a
Refactor Keycloak Postgres extension for code reuse and improved flex…
max2020204 Aug 29, 2025
31a647b
Move Keycloak Postgres extension tests into core Keycloak extensions
max2020204 Aug 29, 2025
cdd4b15
Merge branch 'main' into KeycloakPostgres
max2020204 Sep 6, 2025
1ba736e
Add README and comprehensive tests for Keycloak PostgreSQL integration
max2020204 Sep 6, 2025
1efdbbc
Merge remote-tracking branch 'origin/KeycloakPostgres' into KeycloakP…
max2020204 Sep 6, 2025
afb6c43
Merge branch 'main' into KeycloakPostgres
max2020204 Sep 15, 2025
993aa3e
Merge branch 'main' into KeycloakPostgres
max2020204 Sep 16, 2025
6eeee8c
Remove outdated comment in KeycloakExtensionTests regarding server pa…
max2020204 Sep 16, 2025
8514cab
Merge remote-tracking branch 'origin/KeycloakPostgres' into KeycloakP…
max2020204 Sep 16, 2025
7513876
Add integration tests for Keycloak with Postgres and update project r…
max2020204 Sep 16, 2025
8d7af9f
Add Keycloak Postgres example projects and enhance Aspire integration
max2020204 Sep 16, 2025
2c66428
Remove unused Moq package reference from Keycloak extension tests pro…
max2020204 Sep 16, 2025
d504e4c
Update Keycloak Postgres example projects and dependencies
max2020204 Sep 16, 2025
5db02af
Update Aspire package version references to use variable-based approach
max2020204 Sep 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CommunityToolkit.Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<Project Path="examples/k6/CommunityToolkit.Aspire.Hosting.k6.AppHost/CommunityToolkit.Aspire.Hosting.k6.AppHost.csproj" />
<Project Path="examples/k6/CommunityToolkit.Aspire.Hosting.k6.ServiceDefaults/CommunityToolkit.Aspire.Hosting.k6.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/examples/keycloak-postgres/">
<Project Path="examples\keycloak-postgres\CommunityToolkit.Aspire.Keycloak.Extensions.AppHost.ServiceDefaults\CommunityToolkit.Aspire.Keycloak.Extensions.AppHost.ServiceDefaults.csproj" Type="Classic C#" />
<Project Path="examples\keycloak-postgres\CommunityToolkit.Aspire.Keycloak.Extensions.AppHost\CommunityToolkit.Aspire.Keycloak.Extensions.AppHost.csproj" Type="Classic C#" />
<Project Path="examples\keycloak-postgres\CommunityToolkit.Aspire.Keycloak.Extensions.Dev\CommunityToolkit.Aspire.Keycloak.Extensions.Dev.csproj" Type="Classic C#" />
<Project Path="examples\keycloak-postgres\CommunityToolkit.Aspire.Keycloak.Extensions.Prod\CommunityToolkit.Aspire.Keycloak.Extensions.Prod.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/examples/lavinmq/">
<Project Path="examples/lavinmq/CommunityToolkit.Aspire.Hosting.LavinMQ.AppHost/CommunityToolkit.Aspire.Hosting.LavinMQ.AppHost.csproj" />
<Project Path="examples/lavinmq/CommunityToolkit.Aspire.Hosting.LavinMQ.MassTransit/CommunityToolkit.Aspire.Hosting.LavinMQ.MassTransit.csproj" />
Expand Down Expand Up @@ -153,8 +159,8 @@
</Folder>
<Folder Name="/examples/surrealdb/">
<Project Path="examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.csproj" />
<Project Path="examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ServiceDefaults/CommunityToolkit.Aspire.Hosting.SurrealDb.ServiceDefaults.csproj" />
<Project Path="examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.AppHost/CommunityToolkit.Aspire.Hosting.SurrealDb.AppHost.csproj" />
<Project Path="examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ServiceDefaults/CommunityToolkit.Aspire.Hosting.SurrealDb.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/src/">
<Project Path="src/CommunityToolkit.Aspire.EventStore/CommunityToolkit.Aspire.EventStore.csproj" />
Expand Down Expand Up @@ -201,6 +207,7 @@
<Project Path="src/CommunityToolkit.Aspire.OllamaSharp/CommunityToolkit.Aspire.OllamaSharp.csproj" />
<Project Path="src/CommunityToolkit.Aspire.RavenDB.Client/CommunityToolkit.Aspire.RavenDB.Client.csproj" />
<Project Path="src/CommunityToolkit.Aspire.SurrealDb/CommunityToolkit.Aspire.SurrealDb.csproj" />
<Project Path="src\CommunityToolkit.Aspire.Keycloak.Extensions\CommunityToolkit.Aspire.Keycloak.Extensions.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/src/Dapr/">
<Project Path="src/CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis/CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis.csproj" />
Expand Down Expand Up @@ -253,6 +260,7 @@
<Project Path="tests/CommunityToolkit.Aspire.RavenDB.Client.Tests/CommunityToolkit.Aspire.RavenDB.Client.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.SurrealDb.Tests/CommunityToolkit.Aspire.SurrealDb.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Testing/CommunityToolkit.Aspire.Testing.csproj" />
<Project Path="tests\CommunityToolkit.Aspire.Keycloak.Extensions.Tests\CommunityToolkit.Aspire.Keycloak.Extensions.Tests.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/tests/Dapr/">
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis.Tests/CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis.Tests.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="Aspire.Hosting.Dapr" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Azure.AppContainers" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Azure.Redis" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Keycloak" Version="9.4.1-preview.1.25408.4" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to introduce a MSBuild variable for the preview version of Aspire packages.

<PackageVersion Include="Aspire.Hosting.NodeJS" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Python" Version="$(AspireVersion)" />
Expand All @@ -18,6 +19,7 @@
<PackageVersion Include="Aspire.Hosting.MongoDB" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.MySql" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Keycloak.Authentication" Version="9.4.1-preview.1.25408.4" />
</ItemGroup>
<ItemGroup Label="Core Packages">
<!-- AspNetCore packages -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>

<PackageReference Include="Microsoft.Extensions.Http.Resilience"/>
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery"/>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting"/>
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Http"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

namespace CommunityToolkit.Aspire.Keycloak.Extensions.AppHost.ServiceDefaults;

// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
public static class Extensions
{
private const string HealthEndpointPath = "/health";
private const string AlivenessEndpointPath = "/alive";

public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.ConfigureOpenTelemetry();

builder.AddDefaultHealthChecks();

builder.Services.AddServiceDiscovery();

builder.Services.ConfigureHttpClientDefaults(http =>
{
// Turn on resilience by default
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
// {
// options.AllowedSchemes = ["https"];
// });

return builder;
}

public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation(tracing =>
// Exclude health check requests from tracing
tracing.Filter = context =>
!context.Request.Path.StartsWithSegments(HealthEndpointPath)
&& !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
)
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});

builder.AddOpenTelemetryExporters();

return builder;
}

private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

if (useOtlpExporter)
{
builder.Services.AddOpenTelemetry().UseOtlpExporter();
}

// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
//}

return builder;
}

public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
builder.Services.AddHealthChecks()
// Add a default liveness check to ensure app is responsive
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);

return builder;
}

public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks(HealthEndpointPath);

// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks(AlivenessEndpointPath,
new HealthCheckOptions { Predicate = r => r.Tags.Contains("live") });
}

return app;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Aspire.Hosting;
using CommunityToolkit.Aspire.Keycloak.Extensions;


var builder = DistributedApplication.CreateBuilder(args);

var postgres = builder.AddPostgres("keycloak-postgres-dev");
var dbDev = postgres.AddDatabase("db-dev");

var keycloakDev = builder.AddKeycloak("keycloak-dev")
.WithPostgres(dbDev);

var dbUserName = builder.AddParameter("db-username", "postgres");
var dbPassword = builder.AddParameter("db-password", "Postgres!123");

var postgresProd = builder.AddPostgres("postgres-prod",
dbUserName, dbPassword);

var dbProd = postgresProd.AddDatabase("db-prod");

var keycloakProd = builder.AddKeycloak("keycloak-prod")
.WithPostgres(dbProd, dbUserName, dbPassword);


builder.AddProject<Projects.CommunityToolkit_Aspire_Keycloak_Extensions_Dev>("project-dev")
.WithReference(keycloakDev)
.WaitFor(keycloakDev);

builder.AddProject<Projects.CommunityToolkit_Aspire_Keycloak_Extensions_Prod>("project-prod")
.WithReference(keycloakProd)
.WaitFor(keycloakProd);
builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)"/>

<PropertyGroup>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net9.0</TargetFramework>
<UserSecretsId>e5e65289-cf91-4bda-b628-28a68fb90841</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting"/>
<PackageReference Include="Aspire.Hosting.AppHost"/>
<PackageReference Include="Aspire.Hosting.Keycloak"/>
<PackageReference Include="Aspire.Hosting.PostgreSQL"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Keycloak.Extensions\CommunityToolkit.Aspire.Keycloak.Extensions.csproj" IsAspireProjectResource="false"/>
<ProjectReference Include="..\CommunityToolkit.Aspire.Keycloak.Extensions.Dev\CommunityToolkit.Aspire.Keycloak.Extensions.Dev.csproj"/>
<ProjectReference Include="..\CommunityToolkit.Aspire.Keycloak.Extensions.Prod\CommunityToolkit.Aspire.Keycloak.Extensions.Prod.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17044;http://localhost:15216",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21202",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22139"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15216",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19292",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20099"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Keycloak.Authentication" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Aspire.Keycloak.Extensions.AppHost.ServiceDefaults\CommunityToolkit.Aspire.Keycloak.Extensions.AppHost.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@CommunityToolkit.Aspire.Keycloak.Extensions_HostAddress = http://localhost:5030

GET {{CommunityToolkit.Aspire.Keycloak.Extensions_HostAddress}}/weatherforecast/
Accept: application/json

###
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommunityToolkit.Aspire.Keycloak.Extensions.AppHost.ServiceDefaults;

var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();

builder.Services.AddAuthentication()
.AddKeycloakJwtBearer("keycloak-dev", "master", jwt =>
{
if (builder.Environment.IsDevelopment())
{
//for development only
jwt.RequireHttpsMetadata = false;
}


});

var app = builder.Build();


app.UseHttpsRedirection();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");

app.Run();

record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Loading