-
Notifications
You must be signed in to change notification settings - Fork 129
Add Keycloak with Postgres integration #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 40 commits
0df225d
2e07fa8
1bf7ea7
90621f4
7a4fc17
9b11f66
03cbc0a
53c7ca1
9c913c5
d77acaf
fcfad00
6cd7d93
d4720a9
3962aa1
beb9fe9
e01ce34
19c6f9a
31a647b
cdd4b15
1ba736e
1efdbbc
afb6c43
993aa3e
6eeee8c
8514cab
7513876
8d7af9f
2c66428
d504e4c
5db02af
c5b5d8d
5424687
fe16c1f
50db669
9d0a369
96e174f
fedcf87
6c968b4
b1d9793
a7422fe
bbbb8d4
9055d7b
81bb900
4a801e9
cab3674
1e5d94d
5961fec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
| <AspirePreviewVersion>9.4.1-preview.1.25408.4</AspirePreviewVersion> | ||
| <MoqVersion>4.20.72</MoqVersion> | ||
|
||
| </PropertyGroup> | ||
| <ItemGroup Label="Aspire Packages"> | ||
| <!-- Aspire packages --> | ||
|
|
@@ -18,6 +20,9 @@ | |
| <PackageVersion Include="Aspire.Hosting.MongoDB" Version="$(AspireVersion)" /> | ||
| <PackageVersion Include="Aspire.Hosting.MySql" Version="$(AspireVersion)" /> | ||
| <PackageVersion Include="Aspire.Hosting.SqlServer" Version="$(AspireVersion)" /> | ||
| <PackageVersion Include="Aspire.Hosting.Keycloak" Version="$(AspirePreviewVersion)" /> | ||
| <PackageVersion Include="Aspire.Keycloak.Authentication" Version="$(AspirePreviewVersion)" /> | ||
| <PackageVersion Include="Moq" Version="$(MoqVersion)" /> | ||
|
||
| </ItemGroup> | ||
| <ItemGroup Label="Core Packages"> | ||
| <!-- AspNetCore packages --> | ||
|
|
||
| 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_Hosting_Extensions_Dev>("project-dev") | ||
| .WithReference(keycloakDev) | ||
| .WaitFor(keycloakDev); | ||
|
|
||
| builder.AddProject<Projects.CommunityToolkit_Aspire_Keycloak_Hosting_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.Hosting.Extensions.Dev\CommunityToolkit.Aspire.Keycloak.Hosting.Extensions.Dev.csproj" /> | ||
| <ProjectReference Include="..\CommunityToolkit.Aspire.Keycloak.Hosting.Extensions.Prod\CommunityToolkit.Aspire.Keycloak.Hosting.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,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,19 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||||
|
|
||||
| <PropertyGroup> | ||||
| <TargetFramework>net9.0</TargetFramework> | ||||
| <Nullable>enable</Nullable> | ||||
| <ImplicitUsings>enable</ImplicitUsings> | ||||
| <TargetFrameworks /> | ||||
|
||||
| <TargetFrameworks /> |
Copilot uses AI. Check for mistakes.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using CommunityToolkit.Aspire.Keycloak.Hosting.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); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:5030", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7041;http://localhost:5030", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @CommunityToolkit.Aspire.Keycloak.Extensions.Prod_HostAddress = http://localhost:5286 | ||
|
|
||
| GET {{CommunityToolkit.Aspire.Keycloak.Extensions.Prod_HostAddress}}/weatherforecast/ | ||
| Accept: application/json | ||
|
|
||
| ### |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||||
|
|
||||
| <PropertyGroup> | ||||
| <TargetFramework>net9.0</TargetFramework> | ||||
| <Nullable>enable</Nullable> | ||||
| <ImplicitUsings>enable</ImplicitUsings> | ||||
| <TargetFrameworks /> | ||||
|
||||
| <TargetFrameworks /> |
Copilot uses AI. Check for mistakes.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| using CommunityToolkit.Aspire.Keycloak.Hosting.Extensions.AppHost.ServiceDefaults; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.AddServiceDefaults(); | ||
|
|
||
| builder.Services.AddAuthentication() | ||
| .AddKeycloakJwtBearer("keycloak-prod", "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); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:5286", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7134;http://localhost:5286", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireSharedProject>true</IsAspireSharedProject> | ||
| <RootNamespace>CommunityToolkit.Aspire.Keycloak.Hosting.Extensions.AppHost.ServiceDefaults</RootNamespace> | ||
| </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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This belongs in the
Directory.Build.propsfile, and it should be just the suffix, so that when used we would do<PackageVersion Include="Aspire.Hosting.Keycloak" Version="$(AspireVersion)-$(AspirePreviewSuffix)" />, which ensures that we sync theMajor.Minor.Patchacross all packages.