Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0df225d
**Add Keycloak with Postgres integration**
axies20 Aug 26, 2025
2e07fa8
Refactor Keycloak Postgres extension for improved configuration
axies20 Aug 26, 2025
1bf7ea7
Merge branch 'main' into KeycloakPostgres
axies20 Aug 26, 2025
90621f4
Refactor Keycloak Postgres extension for streamlined configuration
axies20 Aug 26, 2025
7a4fc17
Update src/CommunityToolkit.Aspire.Keycloak.Postgress/KeycloakPostgre…
axies20 Aug 27, 2025
9b11f66
Refactor Keycloak Postgres extension and restructure project
axies20 Aug 27, 2025
03cbc0a
Merge branch 'main' into KeycloakPostgres
axies20 Aug 27, 2025
53c7ca1
Update src/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres/Keycl…
axies20 Aug 28, 2025
9c913c5
Update src/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres/Keycl…
axies20 Aug 28, 2025
d77acaf
Update src/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres/Keycl…
axies20 Aug 28, 2025
fcfad00
Merge remote-tracking branch 'origin/main' into KeycloakPostgres
axies20 Aug 28, 2025
6cd7d93
Merge branch 'main' into KeycloakPostgres
axies20 Aug 28, 2025
d4720a9
Remove Postgres-specific Keycloak extension and merge functionality i…
axies20 Aug 28, 2025
3962aa1
Merge remote-tracking branch 'origin/KeycloakPostgres' into KeycloakP…
axies20 Aug 28, 2025
beb9fe9
Merge branch 'main' into KeycloakPostgres
axies20 Aug 29, 2025
e01ce34
Update tests/CommunityToolkit.Aspire.Keycloak.Extensions.Postgres.Tes…
axies20 Aug 29, 2025
19c6f9a
Refactor Keycloak Postgres extension for code reuse and improved flex…
axies20 Aug 29, 2025
31a647b
Move Keycloak Postgres extension tests into core Keycloak extensions
axies20 Aug 29, 2025
cdd4b15
Merge branch 'main' into KeycloakPostgres
axies20 Sep 6, 2025
1ba736e
Add README and comprehensive tests for Keycloak PostgreSQL integration
axies20 Sep 6, 2025
1efdbbc
Merge remote-tracking branch 'origin/KeycloakPostgres' into KeycloakP…
axies20 Sep 6, 2025
afb6c43
Merge branch 'main' into KeycloakPostgres
axies20 Sep 15, 2025
993aa3e
Merge branch 'main' into KeycloakPostgres
axies20 Sep 16, 2025
6eeee8c
Remove outdated comment in KeycloakExtensionTests regarding server pa…
axies20 Sep 16, 2025
8514cab
Merge remote-tracking branch 'origin/KeycloakPostgres' into KeycloakP…
axies20 Sep 16, 2025
7513876
Add integration tests for Keycloak with Postgres and update project r…
axies20 Sep 16, 2025
8d7af9f
Add Keycloak Postgres example projects and enhance Aspire integration
axies20 Sep 16, 2025
2c66428
Remove unused Moq package reference from Keycloak extension tests pro…
axies20 Sep 16, 2025
d504e4c
Update Keycloak Postgres example projects and dependencies
axies20 Sep 16, 2025
5db02af
Update Aspire package version references to use variable-based approach
axies20 Sep 16, 2025
c5b5d8d
Merge branch 'main' into KeycloakPostgres
axies20 Sep 23, 2025
5424687
Update Directory.Packages.props and Keycloak tests for new package ve…
axies20 Sep 23, 2025
fe16c1f
Merge branch 'main' into KeycloakPostgres
axies20 Sep 28, 2025
50db669
Rename Keycloak Extensions and Examples to use "Hosting" for consistency
axies20 Sep 28, 2025
9d0a369
Merge remote-tracking branch 'origin/KeycloakPostgres' into KeycloakP…
axies20 Sep 28, 2025
96e174f
Merge branch 'main' into KeycloakPostgres
axies20 Oct 1, 2025
fedcf87
Merge branch 'main' into KeycloakPostgres
axies20 Oct 15, 2025
6c968b4
Merge branch 'CommunityToolkit:main' into KeycloakPostgres
axies20 Oct 20, 2025
b1d9793
Rename Keycloak Extensions to "Hosting" for consistency
axies20 Oct 20, 2025
a7422fe
Update Keycloak PostgreSQL extensions for hosting model compliance
axies20 Oct 20, 2025
bbbb8d4
Enhance XML docs for `WithPostgres` methods and fix project references
axies20 Oct 20, 2025
9055d7b
Rename Keycloak Hosting Extensions to Aspire.Hosting for consistency
axies20 Oct 21, 2025
81bb900
Fixing the naming again and some build issues
aaronpowell Oct 22, 2025
4a801e9
Adding the tests in
aaronpowell Oct 22, 2025
cab3674
Fixing more bad changes
aaronpowell Oct 22, 2025
1e5d94d
Dealing with more build errors
aaronpowell Oct 22, 2025
5961fec
Merge branch 'main' into KeycloakPostgres
axies20 Oct 22, 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
6 changes: 4 additions & 2 deletions CommunityToolkit.Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,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 @@ -191,6 +191,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.Postgres\CommunityToolkit.Aspire.Keycloak.Extensions.Postgres.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 @@ -241,6 +242,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.Postgres.Tests\CommunityToolkit.Aspire.Keycloak.Extensions.Postgres.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 All @@ -250,4 +252,4 @@
<Folder Name="/tests/tests-app-hosts/">
<Project Path="tests-app-hosts/Ollama.AppHost/Ollama.AppHost.csproj" />
</Folder>
</Solution>
</Solution>
4 changes: 3 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
</PropertyGroup>
<ItemGroup Label="Aspire Packages">
<!-- Aspire packages -->
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting" Version="9.4.1" />
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is just done when you were testing, but ensure you roll that back and use the MSBuild variable

Copy link
Author

Choose a reason for hiding this comment

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

I had error
0>CommunityToolkit.Aspire.Keycloak.Postgres.csproj: Error NU1605 : Warning As Error: Detected package downgrade: Aspire.Hosting from 9.4.1 to 9.4.0. Reference the package directly from the project to select a different version.
CommunityToolkit.Aspire.Keycloak.Postgres -> Aspire.Hosting.Keycloak 9.4.1-preview.1.25408.4 -> Aspire.Hosting (>= 9.4.1)
CommunityToolkit.Aspire.Keycloak.Postgres -> Aspire.Hosting (>= 9.4.0)
0>------- Finished building project: CommunityToolkit.Aspire.Keycloak.Postgres. Succeeded: False. Errors: 1. Warnings: 0

Copy link
Member

Choose a reason for hiding this comment

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

The main branch is now updated to 9.4.1 Aspire.

<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Azure.Storage" Version="$(AspireVersion)" />
<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="Moq" Version="4.20.72" />
Copy link
Member

Choose a reason for hiding this comment

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

This should be under the Testing item group

</ItemGroup>
<ItemGroup Label="Core Packages">
<!-- AspNetCore packages -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using Npgsql;

namespace CommunityToolkit.Aspire.Keycloak.Extensions.Postgres;

/// <summary>
/// Provides extension methods for integrating Keycloak resources with PostgreSQL.
/// </summary>
public static class KeycloakPostgresExtension
{
/// Configures a Keycloak resource to use a Postgres database by setting appropriate environment variables.
/// <param name="builder">
/// The resource builder for the Keycloak resource.
/// </param>
/// <param name="database">
/// The resource builder for the Postgres database resource.
/// </param>
/// <param name="app">
/// The distributed application builder for adding parameters like username and password for the Postgres database.
/// </param>
/// <returns>
/// The updated resource builder for the Keycloak resource.
/// </returns>
private static void WithPostgres(this IResourceBuilder<KeycloakResource> builder,
Copy link
Contributor

Choose a reason for hiding this comment

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

This will work with dev and production.

Copy link
Author

Choose a reason for hiding this comment

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

You mean void? After that, you can't add other methods, so I returned IResourceBuilder

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I mean that this approach using expressions works in both cases and you don’t need 2 implementations for run and publish

IResourceBuilder<PostgresDatabaseResource> database)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(database);

PostgresServerResource pgServer = database.Resource.Parent;
EndpointReference ep = pgServer.GetEndpoint("tcp");

string dbName = database.Resource.Name;

ReferenceExpression jdbcUrl = ReferenceExpression.Create(
$"jdbc:postgresql://{ep.Property(EndpointProperty.Host)}:" +
$"{ep.Property(EndpointProperty.Port)}/{dbName}");

builder.WithEnvironment("KC_DB", "postgres")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct? Why is this hard coded?

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if postgres is password protected (which is the default).

Copy link
Author

@axies20 axies20 Aug 27, 2025

Choose a reason for hiding this comment

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

builder.WithEnvironment("KC_DB", "postgres")
You about this? Yeah, it's correct. There are other database vendors, but I'm writing for postgres
All environment variables: https://www.keycloak.org/server/all-config
I wanna make for other vendors such as dev-file (default), dev-mem, mariadb, mssql, mysql, oracle, postgres (all vendors that support)

Copy link
Author

Choose a reason for hiding this comment

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

What happens if postgres is password protected (which is the default).

public static IResourceBuilder<KeycloakResource> WithPostgres(this IResourceBuilder<KeycloakResource> builder,
        IResourceBuilder<PostgresDatabaseResource> database, ParameterResource username, ParameterResource password)
    {
        ArgumentNullException.ThrowIfNull(username);
        ArgumentNullException.ThrowIfNull(password);
        WithPostgres(builder, database);
        builder.WithEnvironment("KC_DB_USERNAME", username)
            .WithEnvironment("KC_DB_PASSWORD", password);
        return builder;
    }

Here I'm setting by parameter that will set up from user, or what you mean?

.WithEnvironment("KC_DB_URL", jdbcUrl);
}

/// Configures a Keycloak resource to use a Postgres database in a development environment by setting appropriate
/// environment variables and custom connection details.
/// <param name="builder">
/// The resource builder for the Keycloak resource.
/// </param>
/// <param name="database">
/// The resource builder for the Postgres database resource.
/// </param>
/// <param name="port">
/// The port for connecting to the Postgres database. Defaults to 5432.
/// </param>
/// <returns>
/// The updated resource builder for the Keycloak resource.
/// </returns>
public static IResourceBuilder<KeycloakResource> WithPostgresDev(this IResourceBuilder<KeycloakResource> builder,
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this overload at all.

Copy link
Author

Choose a reason for hiding this comment

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

You said that event will not work in prod, so I thought that this i will leave for the development environment

Copy link
Contributor

Choose a reason for hiding this comment

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

Right so you don’t need this

Copy link
Member

Choose a reason for hiding this comment

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

There can be conditional logic to check for the different modes rather than having to call different methods.

IResourceBuilder<PostgresDatabaseResource> database, int port = 5432)
{
WithPostgres(builder, database);

database.OnConnectionStringAvailable(async (dataResource, _, cancellationToken) =>
{
NpgsqlConnectionStringBuilder npg =
new(await dataResource.ConnectionStringExpression.GetValueAsync(cancellationToken));
builder.WithEnvironment("KC_DB", "postgres")
.WithEnvironment("KC_DB", "postgres")
Copy link

Copilot AI Aug 28, 2025

Choose a reason for hiding this comment

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

The environment variable 'KC_DB' is being set twice with the same value 'postgres'. Remove the duplicate line 68.

Suggested change
builder.WithEnvironment("KC_DB", "postgres")
.WithEnvironment("KC_DB", "postgres")

Copilot uses AI. Check for mistakes.

.WithEnvironment("KC_DB_URL",
$"jdbc:postgresql://{dataResource.Parent.Name}:{port.ToString()}/{npg.Database}")
.WithEnvironment("KC_DB_USERNAME", npg.Username)
.WithEnvironment("KC_DB_PASSWORD", npg.Password);
});
return builder;
}


/// Configures a Keycloak resource to use a Postgres database by setting appropriate environment variables, including credentials.
/// <param name="builder">
/// The resource builder for the Keycloak resource.
/// </param>
/// <param name="database">
/// The resource builder for the Postgres database resource.
/// </param>
/// <param name="username">
/// The parameter resource representing the username for the Postgres database.
/// </param>
/// <param name="password">
/// The parameter resource representing the password for the Postgres database.
/// </param>
/// <returns>
/// The updated resource builder for the Keycloak resource.
/// </returns>
public static IResourceBuilder<KeycloakResource> WithPostgres(this IResourceBuilder<KeycloakResource> builder,
IResourceBuilder<PostgresDatabaseResource> database, ParameterResource username, ParameterResource password)
{
ArgumentNullException.ThrowIfNull(username);
ArgumentNullException.ThrowIfNull(password);
WithPostgres(builder, database);
builder.WithEnvironment("KC_DB_USERNAME", username)
.WithEnvironment("KC_DB_PASSWORD", password);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
Copy link
Member

Choose a reason for hiding this comment

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

These aren't needed as they are inherited. Check the other test projects and follow their patterns


<ItemGroup>
<PackageReference Include="Aspire.Hosting.Keycloak" />
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
Copy link
Member

Choose a reason for hiding this comment

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

These will fail the build as CPM dictates versions

</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\CommunityToolkit.Aspire.Keycloak.Extensions.Postgres\CommunityToolkit.Aspire.Keycloak.Extensions.Postgres.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


namespace CommunityToolkit.Aspire.Keycloak.Extensions.Postgres.Tests;

public partial class KeycloakExtensionPostgressTests
{

}