Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
</PropertyGroup>


<ItemGroup>
<ProjectReference Include="..\..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
<PackageReference Include="Duende.IdentityModel" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Console.Title = "Client";

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

builder.Services.AddControllersWithViews();

Expand Down Expand Up @@ -62,6 +63,7 @@
app.UseAuthentication();
app.UseAuthorization();

app.MapDefaultEndpoints();
app.MapDefaultControllerRoute().RequireAuthorization();

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServerHost", "Ident
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{85CD36E8-3402-443B-859A-72E4B9390E8B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.AppHost", "IdentityServer.AppHost\IdentityServer.AppHost.csproj", "{E8BA4D90-0AF7-4FA3-9F0D-5A11D98C0640}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.ServiceDefaults", "..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj", "{4259ED99-4121-4E62-83C5-CC0699BC389A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +25,14 @@ Global
{85CD36E8-3402-443B-859A-72E4B9390E8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85CD36E8-3402-443B-859A-72E4B9390E8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85CD36E8-3402-443B-859A-72E4B9390E8B}.Release|Any CPU.Build.0 = Release|Any CPU
{E8BA4D90-0AF7-4FA3-9F0D-5A11D98C0640}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8BA4D90-0AF7-4FA3-9F0D-5A11D98C0640}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8BA4D90-0AF7-4FA3-9F0D-5A11D98C0640}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8BA4D90-0AF7-4FA3-9F0D-5A11D98C0640}.Release|Any CPU.Build.0 = Release|Any CPU
{4259ED99-4121-4E62-83C5-CC0699BC389A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4259ED99-4121-4E62-83C5-CC0699BC389A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4259ED99-4121-4E62-83C5-CC0699BC389A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4259ED99-4121-4E62-83C5-CC0699BC389A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var builder = DistributedApplication.CreateBuilder(args);
var idsvr = builder.AddProject<Projects.IdentityServerHost>("identityserverhost");
builder.AddProject<Projects.Client>("client")
.WaitFor(idsvr);
builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Aspire.AppHost.Sdk/13.2.2">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<ProjectReference Include="..\Client\Client.csproj" />
<ProjectReference Include="..\IdentityServerHost\IdentityServerHost.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17196;http://localhost:15048",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21100",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23036",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22230"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15048",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19122",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18210",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20059"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
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
Expand Up @@ -5,10 +5,11 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Duende.IdentityServer.EntityFramework" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.WsFederation" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,32 @@
using IdentityServerHost;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.EntityFrameworkCore;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;

Console.Title = "IdentityServer";

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

var seed = args.Contains("/seed");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Random thought (also for some other samples) - is it worth adding a command to the apphost/dashboard to seed database?

if (seed)
{
args = args.Except(new[] { "/seed" }).ToArray();
}

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSerilog();
builder.AddServiceDefaults();

builder.Services.AddRazorPages();

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");

if (seed)
{
Log.Information("Seeding database...");
Console.WriteLine("Seeding database...");
SeedData.EnsureSeedData(connectionString);
Log.Information("Done seeding database.");
Console.WriteLine("Done seeding database.");
return;
}

builder.Services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;

// see https://docs.duendesoftware.com/identityserver/fundamentals/resources
options.EmitStaticAudienceClaim = true;

Expand Down Expand Up @@ -106,6 +93,7 @@
app.UseRouting();
app.UseIdentityServer();
app.UseAuthorization();
app.MapDefaultEndpoints();
app.MapRazorPages();

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Duende.IdentityServer.EntityFramework.Storage;
using Duende.IdentityServer.Models;
using Microsoft.EntityFrameworkCore;
using Serilog;

namespace IdentityServerHost;

Expand Down Expand Up @@ -40,7 +39,7 @@ private static void EnsureSeedData(ConfigurationDbContext context)
{
if (!context.Clients.Any())
{
Log.Debug("Clients being populated");
Console.WriteLine("Clients being populated");
foreach (var client in Config.Clients.ToList())
{
context.Clients.Add(client.ToEntity());
Expand All @@ -49,12 +48,12 @@ private static void EnsureSeedData(ConfigurationDbContext context)
}
else
{
Log.Debug("Clients already populated");
Console.WriteLine("Clients already populated");
}

if (!context.IdentityResources.Any())
{
Log.Debug("IdentityResources being populated");
Console.WriteLine("IdentityResources being populated");
foreach (var resource in Config.IdentityResources.ToList())
{
context.IdentityResources.Add(resource.ToEntity());
Expand All @@ -63,12 +62,12 @@ private static void EnsureSeedData(ConfigurationDbContext context)
}
else
{
Log.Debug("IdentityResources already populated");
Console.WriteLine("IdentityResources already populated");
}

if (!context.ApiScopes.Any())
{
Log.Debug("ApiScopes being populated");
Console.WriteLine("ApiScopes being populated");
foreach (var apiScope in Config.ApiScopes.ToList())
{
context.ApiScopes.Add(apiScope.ToEntity());
Expand All @@ -77,7 +76,7 @@ private static void EnsureSeedData(ConfigurationDbContext context)
}
else
{
Log.Debug("ApiScopes already populated");
Console.WriteLine("ApiScopes already populated");
}

if (!context.IdentityProviders.Any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Console.Title = "Client";

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

builder.Services.AddControllersWithViews();

Expand Down Expand Up @@ -62,6 +63,7 @@
app.UseAuthentication();
app.UseAuthorization();

app.MapDefaultEndpoints();
app.MapDefaultControllerRoute().RequireAuthorization();

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServerHost", "Ident
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{85CD36E8-3402-443B-859A-72E4B9390E8B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.AppHost", "IdentityServer.AppHost\IdentityServer.AppHost.csproj", "{721009DF-B8CB-42BB-8E97-6AF070D9F4DB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.ServiceDefaults", "..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj", "{48840739-F37C-4710-B254-9E3BF8B564A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +25,14 @@ Global
{85CD36E8-3402-443B-859A-72E4B9390E8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85CD36E8-3402-443B-859A-72E4B9390E8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85CD36E8-3402-443B-859A-72E4B9390E8B}.Release|Any CPU.Build.0 = Release|Any CPU
{721009DF-B8CB-42BB-8E97-6AF070D9F4DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{721009DF-B8CB-42BB-8E97-6AF070D9F4DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{721009DF-B8CB-42BB-8E97-6AF070D9F4DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{721009DF-B8CB-42BB-8E97-6AF070D9F4DB}.Release|Any CPU.Build.0 = Release|Any CPU
{48840739-F37C-4710-B254-9E3BF8B564A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48840739-F37C-4710-B254-9E3BF8B564A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48840739-F37C-4710-B254-9E3BF8B564A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48840739-F37C-4710-B254-9E3BF8B564A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var builder = DistributedApplication.CreateBuilder(args);

var idsvr = builder.AddProject<Projects.IdentityServerHost>("identityserverhost");

builder.AddProject<Projects.Client>("client")
.WaitFor(idsvr);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Aspire.AppHost.Sdk/13.2.1">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<ProjectReference Include="..\Client\Client.csproj" />
<ProjectReference Include="..\IdentityServerHost\IdentityServerHost.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17197;http://localhost:15148",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21120",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23015",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22043"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15148",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19107",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18254",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20078"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
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
Expand Up @@ -5,10 +5,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.EntityFramework" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.WsFederation" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
Expand Down
Loading
Loading