Skip to content

Commit 724a1de

Browse files
authored
Add Keycloak component (#4289)
* Add Keycloak component
1 parent 284e5a3 commit 724a1de

File tree

58 files changed

+3831
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3831
-0
lines changed

Aspire.sln

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Python.Tests
533533
EndProject
534534
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Valkey.Tests", "tests\Aspire.Hosting.Valkey.Tests\Aspire.Hosting.Valkey.Tests.csproj", "{1C16DC2D-3B79-4081-AC1E-F3F965C61216}"
535535
EndProject
536+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Keycloak.Authentication", "src\Components\Aspire.Keycloak.Authentication\Aspire.Keycloak.Authentication.csproj", "{C87D9F7D-300A-4880-A7E1-835772749912}"
537+
EndProject
538+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Keycloak", "src\Aspire.Hosting.Keycloak\Aspire.Hosting.Keycloak.csproj", "{1F8D77E1-AF1B-4CCA-A2CB-12AB40282B40}"
539+
EndProject
540+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "keycloak", "keycloak", "{EBC55A17-B0D6-4E0A-9DC2-7D264E96F631}"
541+
EndProject
542+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Keycloak.ApiService", "playground\keycloak\Keycloak.ApiService\Keycloak.ApiService.csproj", "{14BA6E7B-1726-4F23-9C32-72B953BC392B}"
543+
EndProject
544+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Keycloak.Web", "playground\keycloak\Keycloak.Web\Keycloak.Web.csproj", "{0BE14FA4-3F09-426D-BF5A-F9102D36DE33}"
545+
EndProject
546+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Keycloak.AppHost", "playground\keycloak\Keycloak.AppHost\Keycloak.AppHost.csproj", "{C556D61C-7E11-43EC-9098-C8D170FEA905}"
547+
EndProject
548+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Keycloak.Tests", "tests\Aspire.Hosting.Keycloak.Tests\Aspire.Hosting.Keycloak.Tests.csproj", "{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD}"
549+
EndProject
550+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Keycloak.Authentication.Tests", "tests\Aspire.Keycloak.Authentication.Tests\Aspire.Keycloak.Authentication.Tests.csproj", "{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}"
551+
EndProject
536552
Global
537553
GlobalSection(SolutionConfigurationPlatforms) = preSolution
538554
Debug|Any CPU = Debug|Any CPU
@@ -1395,6 +1411,34 @@ Global
13951411
{1C16DC2D-3B79-4081-AC1E-F3F965C61216}.Debug|Any CPU.Build.0 = Debug|Any CPU
13961412
{1C16DC2D-3B79-4081-AC1E-F3F965C61216}.Release|Any CPU.ActiveCfg = Release|Any CPU
13971413
{1C16DC2D-3B79-4081-AC1E-F3F965C61216}.Release|Any CPU.Build.0 = Release|Any CPU
1414+
{C87D9F7D-300A-4880-A7E1-835772749912}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1415+
{C87D9F7D-300A-4880-A7E1-835772749912}.Debug|Any CPU.Build.0 = Debug|Any CPU
1416+
{C87D9F7D-300A-4880-A7E1-835772749912}.Release|Any CPU.ActiveCfg = Release|Any CPU
1417+
{C87D9F7D-300A-4880-A7E1-835772749912}.Release|Any CPU.Build.0 = Release|Any CPU
1418+
{1F8D77E1-AF1B-4CCA-A2CB-12AB40282B40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1419+
{1F8D77E1-AF1B-4CCA-A2CB-12AB40282B40}.Debug|Any CPU.Build.0 = Debug|Any CPU
1420+
{1F8D77E1-AF1B-4CCA-A2CB-12AB40282B40}.Release|Any CPU.ActiveCfg = Release|Any CPU
1421+
{1F8D77E1-AF1B-4CCA-A2CB-12AB40282B40}.Release|Any CPU.Build.0 = Release|Any CPU
1422+
{14BA6E7B-1726-4F23-9C32-72B953BC392B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1423+
{14BA6E7B-1726-4F23-9C32-72B953BC392B}.Debug|Any CPU.Build.0 = Debug|Any CPU
1424+
{14BA6E7B-1726-4F23-9C32-72B953BC392B}.Release|Any CPU.ActiveCfg = Release|Any CPU
1425+
{14BA6E7B-1726-4F23-9C32-72B953BC392B}.Release|Any CPU.Build.0 = Release|Any CPU
1426+
{0BE14FA4-3F09-426D-BF5A-F9102D36DE33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1427+
{0BE14FA4-3F09-426D-BF5A-F9102D36DE33}.Debug|Any CPU.Build.0 = Debug|Any CPU
1428+
{0BE14FA4-3F09-426D-BF5A-F9102D36DE33}.Release|Any CPU.ActiveCfg = Release|Any CPU
1429+
{0BE14FA4-3F09-426D-BF5A-F9102D36DE33}.Release|Any CPU.Build.0 = Release|Any CPU
1430+
{C556D61C-7E11-43EC-9098-C8D170FEA905}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1431+
{C556D61C-7E11-43EC-9098-C8D170FEA905}.Debug|Any CPU.Build.0 = Debug|Any CPU
1432+
{C556D61C-7E11-43EC-9098-C8D170FEA905}.Release|Any CPU.ActiveCfg = Release|Any CPU
1433+
{C556D61C-7E11-43EC-9098-C8D170FEA905}.Release|Any CPU.Build.0 = Release|Any CPU
1434+
{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1435+
{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
1436+
{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
1437+
{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD}.Release|Any CPU.Build.0 = Release|Any CPU
1438+
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1439+
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
1440+
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
1441+
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7}.Release|Any CPU.Build.0 = Release|Any CPU
13981442
EndGlobalSection
13991443
GlobalSection(SolutionProperties) = preSolution
14001444
HideSolutionNode = FALSE
@@ -1650,6 +1694,14 @@ Global
16501694
{8E2AA85E-C351-47B4-AF91-58557FAD5840} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
16511695
{0A83AA67-221E-44B4-9BA9-DC64DC17949E} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
16521696
{1C16DC2D-3B79-4081-AC1E-F3F965C61216} = {830A89EC-4029-4753-B25A-068BAE37DEC7}
1697+
{C87D9F7D-300A-4880-A7E1-835772749912} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
1698+
{1F8D77E1-AF1B-4CCA-A2CB-12AB40282B40} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
1699+
{EBC55A17-B0D6-4E0A-9DC2-7D264E96F631} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
1700+
{14BA6E7B-1726-4F23-9C32-72B953BC392B} = {EBC55A17-B0D6-4E0A-9DC2-7D264E96F631}
1701+
{0BE14FA4-3F09-426D-BF5A-F9102D36DE33} = {EBC55A17-B0D6-4E0A-9DC2-7D264E96F631}
1702+
{C556D61C-7E11-43EC-9098-C8D170FEA905} = {EBC55A17-B0D6-4E0A-9DC2-7D264E96F631}
1703+
{5867BAF2-FEF0-4661-BFDE-9ADCDC2921CD} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
1704+
{48FF09E9-7D33-4A3F-9FF2-4C43A219C7B7} = {C424395C-1235-41A4-BF55-07880A04368C}
16531705
EndGlobalSection
16541706
GlobalSection(ExtensibilityGlobals) = postSolution
16551707
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<PackageVersion Include="Azure.Provisioning.WebPubSub" Version="0.1.0-beta.1" />
5454
<!-- ASP.NET Core dependencies -->
5555
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Certificate" Version="$(MicrosoftAspNetCoreAuthenticationCertificatePackageVersion)" />
56+
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion)" />
5657
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion)" />
5758
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(MicrosoftAspNetCoreOpenApiPackageVersion)" />
5859
<PackageVersion Include="Microsoft.AspNetCore.OutputCaching.StackExchangeRedis" Version="$(MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion)" />

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<MicrosoftExtensionsOptionsPackageVersion>8.0.2</MicrosoftExtensionsOptionsPackageVersion>
4646
<MicrosoftExtensionsPrimitivesPackageVersion>8.0.0</MicrosoftExtensionsPrimitivesPackageVersion>
4747
<MicrosoftAspNetCoreAuthenticationCertificatePackageVersion>8.0.6</MicrosoftAspNetCoreAuthenticationCertificatePackageVersion>
48+
<MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>8.0.6</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>
4849
<MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>8.0.6</MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>
4950
<MicrosoftAspNetCoreOpenApiPackageVersion>8.0.6</MicrosoftAspNetCoreOpenApiPackageVersion>
5051
<MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion>8.0.6</MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\..\src\Components\Aspire.Keycloak.Authentication\Aspire.Keycloak.Authentication.csproj" />
11+
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add service defaults & Aspire components.
4+
builder.AddServiceDefaults();
5+
6+
// Add services to the container.
7+
builder.Services.AddProblemDetails();
8+
9+
builder.Services.AddAuthentication()
10+
.AddKeycloakJwtBearer("keycloak", realm: "WeatherShop", options =>
11+
{
12+
options.RequireHttpsMetadata = false;
13+
options.Audience = "weather.api";
14+
});
15+
16+
builder.Services.AddAuthorizationBuilder();
17+
18+
var app = builder.Build();
19+
20+
// Configure the HTTP request pipeline.
21+
app.UseExceptionHandler();
22+
23+
var summaries = new[]
24+
{
25+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
26+
};
27+
28+
app.MapGet("/weatherforecast", () =>
29+
{
30+
var forecast = Enumerable.Range(1, 5).Select(index =>
31+
new WeatherForecast
32+
(
33+
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
34+
Random.Shared.Next(-20, 55),
35+
summaries[Random.Shared.Next(summaries.Length)]
36+
))
37+
.ToArray();
38+
return forecast;
39+
})
40+
.RequireAuthorization();
41+
42+
app.MapDefaultEndpoints();
43+
44+
app.Run();
45+
46+
sealed record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
47+
{
48+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
49+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"launchUrl": "weatherforecast",
9+
"applicationUrl": "http://localhost:5502",
10+
"environmentVariables": {
11+
"ASPNETCORE_ENVIRONMENT": "Development"
12+
}
13+
},
14+
"https": {
15+
"commandName": "Project",
16+
"dotnetRunMessages": true,
17+
"launchBrowser": true,
18+
"launchUrl": "weatherforecast",
19+
"applicationUrl": "https://localhost:7492;http://localhost:5502",
20+
"environmentVariables": {
21+
"ASPNETCORE_ENVIRONMENT": "Development"
22+
}
23+
}
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
4+
5+
<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
6+
<Import Project="../../../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.props" />
7+
8+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
4+
5+
<!-- NOTE: These lines are only required because we are using P2P references, not NuGet. They will not exist in real apps. -->
6+
<Import Project="..\..\..\src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets" />
7+
<Import Project="..\..\..\src\Aspire.Hosting.Sdk\SDK\Sdk.targets" />
8+
9+
</Project>

0 commit comments

Comments
 (0)