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 @@ -8,7 +8,7 @@
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Serilog;
using Microsoft.Extensions.Hosting;

namespace IdentityServer;

Expand All @@ -23,11 +23,6 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde
var isBuilder = 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 @@ -105,13 +100,13 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde

public static WebApplication ConfigurePipeline(this WebApplication app)
{
app.UseSerilogRequestLogging();

if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.MapDefaultEndpoints();

app.UseStaticFiles();
app.UseRouting();
app.UseIdentityServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.EntityFramework" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" >
Expand All @@ -20,5 +19,7 @@
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>
</Project>
23 changes: 7 additions & 16 deletions IdentityServer/v7/Configuration/IdentityServerHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@

using System.Globalization;
using IdentityServer;
using Serilog;
using Microsoft.Extensions.Hosting;

Console.Title = "IdentityServer Host";

Log.Logger = new LoggerConfiguration()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.CreateBootstrapLogger();

Log.Information("Starting up");

try
{
var builder = WebApplication.CreateBuilder(args);

builder.Host.UseSerilog((ctx, lc) => lc
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", formatProvider: CultureInfo.InvariantCulture)
.Enrich.FromLogContext()
.ReadFrom.Configuration(ctx.Configuration));
builder.AddServiceDefaults();

var app = builder
.ConfigureServices()
Expand All @@ -30,9 +21,9 @@
// in production you will likely want a different approach.
if (args.Contains("/seed"))
{
Log.Information("Seeding database...");
Console.WriteLine("Seeding database...");
SeedData.EnsureSeedData(app);
Log.Information("Done seeding database. Exiting.");
Console.WriteLine("Done seeding database. Exiting.");
return;
}

Expand All @@ -46,10 +37,10 @@
&& ex.GetType().Name is not "HostAbortedException"
)
{
Log.Fatal(ex, "Unhandled exception");
Console.WriteLine("Unhandled exception");
Console.WriteLine(ex);
}
finally
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
Console.WriteLine("Shut down complete");
}
21 changes: 10 additions & 11 deletions IdentityServer/v7/Configuration/IdentityServerHost/SeedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Duende.IdentityServer.EntityFramework.Mappers;
using Duende.IdentityServer.Models;
using Microsoft.EntityFrameworkCore;
using Serilog;

namespace IdentityServer;

Expand All @@ -27,7 +26,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 @@ -36,12 +35,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 @@ -50,12 +49,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 @@ -64,12 +63,12 @@ private static void EnsureSeedData(ConfigurationDbContext context)
}
else
{
Log.Debug("ApiScopes already populated");
Console.WriteLine("ApiScopes already populated");
}

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

if (!context.IdentityProviders.Any())
{
Log.Debug("OIDC IdentityProviders being populated");
Console.WriteLine("OIDC IdentityProviders being populated");
context.IdentityProviders.Add(new OidcProvider
{
Scheme = "demoidsrv",
Expand All @@ -95,7 +94,7 @@ private static void EnsureSeedData(ConfigurationDbContext context)
}
else
{
Log.Debug("OIDC IdentityProviders already populated");
Console.WriteLine("OIDC IdentityProviders already populated");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
using Duende.IdentityServer.EntityFramework.DbContexts;
using Duende.IdentityServer.EntityFramework.Storage;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;

Console.Title = "Configuration API";

var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.Services.AddIdentityServerConfiguration(opt => { })
.AddClientConfigurationStore();

Expand Down Expand Up @@ -44,6 +46,8 @@

var app = builder.Build();

app.MapDefaultEndpoints();

app.UseAuthentication();
app.UseAuthorization();
app.MapDynamicClientRegistration().RequireAuthorization("DCR");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var builder = DistributedApplication.CreateBuilder(args);

var idp = builder.AddProject<Projects.IdentityServer>("identityserverhost");

var configuration = builder.AddProject<Projects.Configuration>("configuration-api")
.WaitFor(idp);

builder.AddProject<Projects.SimpleApi>("simple-api")
.WaitFor(idp);

builder.AddProject<Projects.ConsoleDcrClient>("console-dcr-client")
.WaitFor(idp)
.WaitFor(configuration);

idp.WithCommand(
name: "seed",
displayName: "Seed Database",
executeCommand: async (context) =>
{
var projectMetadata = idp.Resource.GetProjectMetadata();
var projectPath = projectMetadata.ProjectPath;
var process = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project \"{projectPath}\" --no-build -- /seed",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};

process.Start();
await process.WaitForExitAsync(context.CancellationToken);

if (process.ExitCode == 0)
{
return CommandResults.Success();
}
else
{
var error = await process.StandardError.ReadToEndAsync();
return CommandResults.Failure(error);
}
},
commandOptions: new CommandOptions
{
IconName = "DatabaseArrowUp",
IsHighlighted = true
});

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\IdentityServerHost\IdentityServer.csproj" />
<ProjectReference Include="..\Configuration\Configuration.csproj" />
<ProjectReference Include="..\ConsoleDcrClient\ConsoleDcrClient.csproj" />
<ProjectReference Include="..\..\..\Apis\SimpleApi\SimpleApi.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:17049;http://localhost:15292",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21176",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23177",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22125"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15292",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19221",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18150",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035"
}
}
}
}
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"
}
}
}
Loading
Loading