From dcb64d3d5611a98ea67ba435a5352266a0ccfe00 Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Wed, 8 Jan 2025 16:11:45 -0600 Subject: [PATCH] identityserver hosts and templates - summarize license usage on shutdown --- bff/samples/Bff.DPoP/Bff.DPoP.csproj | 2 +- bff/samples/Bff/Bff.csproj | 2 +- .../IdentityServer/IdentityServer.csproj | 2 +- .../src/ConsoleResourceIndicators/Program.cs | 2 +- .../hosts/AspNetIdentity/Program.cs | 29 +++++++++++++++-- .../hosts/Configuration/Program.cs | 27 +++++++++++++++- .../hosts/EntityFramework/Program.cs | 27 +++++++++++++++- identity-server/hosts/main/Program.cs | 13 +++++--- templates/src/BffLocalApi/BffLocalApi.csproj | 2 +- .../IdentityServerAspNetIdentity.csproj | 16 +++++----- .../Pages/Account/Logout/Index.cshtml.cs | 2 +- .../Pages/Consent/Index.cshtml.cs | 2 +- .../Pages/Diagnostics/ViewModel.cs | 2 +- .../Pages/ExternalLogin/Callback.cshtml.cs | 2 +- .../IdentityServerAspNetIdentity/Program.cs | 30 +++++++++++++++-- .../IdentityServerAspNetIdentity/SeedData.cs | 2 +- .../IdentityServerEmpty.csproj | 4 +-- templates/src/IdentityServerEmpty/Program.cs | 32 +++++++++++++++++-- .../IdentityServerEntityFramework.csproj | 12 +++---- .../Pages/Account/Logout/Index.cshtml.cs | 2 +- .../Pages/Admin/Clients/New.cshtml.cs | 2 +- .../Pages/Consent/Index.cshtml.cs | 2 +- .../Pages/Diagnostics/ViewModel.cs | 2 +- .../Pages/ExternalLogin/Callback.cshtml.cs | 2 +- .../Pages/TestUsers.cs | 2 +- .../IdentityServerEntityFramework/Program.cs | 30 +++++++++++++++-- .../IdentityServerInMem.csproj | 6 ++-- .../Pages/Account/Logout/Index.cshtml.cs | 2 +- .../Pages/Consent/Index.cshtml.cs | 2 +- .../Pages/Diagnostics/ViewModel.cs | 2 +- .../Pages/ExternalLogin/Callback.cshtml.cs | 2 +- .../IdentityServerInMem/Pages/TestUsers.cs | 2 +- templates/src/IdentityServerInMem/Program.cs | 32 +++++++++++++++++-- 33 files changed, 242 insertions(+), 58 deletions(-) diff --git a/bff/samples/Bff.DPoP/Bff.DPoP.csproj b/bff/samples/Bff.DPoP/Bff.DPoP.csproj index 63f61997a..f10b7f6c5 100644 --- a/bff/samples/Bff.DPoP/Bff.DPoP.csproj +++ b/bff/samples/Bff.DPoP/Bff.DPoP.csproj @@ -8,7 +8,7 @@ - + diff --git a/bff/samples/Bff/Bff.csproj b/bff/samples/Bff/Bff.csproj index 05c382c5a..e5d45a53d 100644 --- a/bff/samples/Bff/Bff.csproj +++ b/bff/samples/Bff/Bff.csproj @@ -7,7 +7,7 @@ - + diff --git a/bff/samples/IdentityServer/IdentityServer.csproj b/bff/samples/IdentityServer/IdentityServer.csproj index cada84c36..c11c170f1 100644 --- a/bff/samples/IdentityServer/IdentityServer.csproj +++ b/bff/samples/IdentityServer/IdentityServer.csproj @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/identity-server/clients/src/ConsoleResourceIndicators/Program.cs b/identity-server/clients/src/ConsoleResourceIndicators/Program.cs index a69d57fb3..1ccc8c57a 100644 --- a/identity-server/clients/src/ConsoleResourceIndicators/Program.cs +++ b/identity-server/clients/src/ConsoleResourceIndicators/Program.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using IdentityModel; +using Duende.IdentityModel; using IdentityModel.Client; namespace ConsoleResourceIndicators diff --git a/identity-server/hosts/AspNetIdentity/Program.cs b/identity-server/hosts/AspNetIdentity/Program.cs index dc4d05362..2a36cdaea 100644 --- a/identity-server/hosts/AspNetIdentity/Program.cs +++ b/identity-server/hosts/AspNetIdentity/Program.cs @@ -1,11 +1,13 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using Duende.IdentityServer.Licensing; using IdentityServerHost; using Serilog; -using System.Globalization; using Serilog.Events; using Serilog.Sinks.SystemConsole.Themes; +using System.Globalization; +using System.Text; Console.Title = "IdentityServer (AspNetIdentity)"; @@ -36,6 +38,16 @@ .ConfigureServices() .ConfigurePipeline(); + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } + app.Run(); } catch (Exception ex) @@ -46,4 +58,17 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} + +static string Summary(LicenseUsageSummary usage) +{ + var sb = new StringBuilder(); + sb.AppendLine("IdentityServer Usage Summary:"); + sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}"); + var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None"; + sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used"); + + return sb.ToString(); +} diff --git a/identity-server/hosts/Configuration/Program.cs b/identity-server/hosts/Configuration/Program.cs index 994ad60c7..027dad49a 100644 --- a/identity-server/hosts/Configuration/Program.cs +++ b/identity-server/hosts/Configuration/Program.cs @@ -1,11 +1,13 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using Duende.IdentityServer.Licensing; using IdentityServerHost; using Serilog; using Serilog.Events; using Serilog.Sinks.SystemConsole.Themes; using System.Globalization; +using System.Text; Console.Title = "IdentityServer (Configuration)"; @@ -36,6 +38,16 @@ .ConfigureServices() .ConfigurePipeline(); + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } + app.Run(); } catch (Exception ex) @@ -46,4 +58,17 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} + +static string Summary(LicenseUsageSummary usage) +{ + var sb = new StringBuilder(); + sb.AppendLine("IdentityServer Usage Summary:"); + sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}"); + var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None"; + sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used"); + + return sb.ToString(); +} diff --git a/identity-server/hosts/EntityFramework/Program.cs b/identity-server/hosts/EntityFramework/Program.cs index a57f36ab8..e4fb0ec33 100644 --- a/identity-server/hosts/EntityFramework/Program.cs +++ b/identity-server/hosts/EntityFramework/Program.cs @@ -1,11 +1,13 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. +using Duende.IdentityServer.Licensing; using IdentityServerHost; using Serilog; using Serilog.Events; using Serilog.Sinks.SystemConsole.Themes; using System.Globalization; +using System.Text; Console.Title = "IdentityServer (EntityFramework)"; @@ -36,6 +38,16 @@ .ConfigureServices() .ConfigurePipeline(); + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } + app.Run(); } catch (Exception ex) @@ -46,4 +58,17 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} + +static string Summary(LicenseUsageSummary usage) +{ + var sb = new StringBuilder(); + sb.AppendLine("IdentityServer Usage Summary:"); + sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}"); + var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None"; + sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used"); + + return sb.ToString(); +} diff --git a/identity-server/hosts/main/Program.cs b/identity-server/hosts/main/Program.cs index cee27845f..874429f50 100644 --- a/identity-server/hosts/main/Program.cs +++ b/identity-server/hosts/main/Program.cs @@ -38,12 +38,17 @@ .ConfigureServices() .ConfigurePipeline(); - var usage = app.Services.GetRequiredService(); + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } app.Run(); - - Console.Write(Summary(usage)); - Console.ReadKey(); } catch (Exception ex) { diff --git a/templates/src/BffLocalApi/BffLocalApi.csproj b/templates/src/BffLocalApi/BffLocalApi.csproj index 51173409b..b777950a1 100644 --- a/templates/src/BffLocalApi/BffLocalApi.csproj +++ b/templates/src/BffLocalApi/BffLocalApi.csproj @@ -7,7 +7,7 @@ - + diff --git a/templates/src/IdentityServerAspNetIdentity/IdentityServerAspNetIdentity.csproj b/templates/src/IdentityServerAspNetIdentity/IdentityServerAspNetIdentity.csproj index 40c99bd83..19d23c331 100644 --- a/templates/src/IdentityServerAspNetIdentity/IdentityServerAspNetIdentity.csproj +++ b/templates/src/IdentityServerAspNetIdentity/IdentityServerAspNetIdentity.csproj @@ -7,15 +7,15 @@ - + - - + + - - - - - + + + + + \ No newline at end of file diff --git a/templates/src/IdentityServerAspNetIdentity/Pages/Account/Logout/Index.cshtml.cs b/templates/src/IdentityServerAspNetIdentity/Pages/Account/Logout/Index.cshtml.cs index d9a5231d2..995b26f6b 100644 --- a/templates/src/IdentityServerAspNetIdentity/Pages/Account/Logout/Index.cshtml.cs +++ b/templates/src/IdentityServerAspNetIdentity/Pages/Account/Logout/Index.cshtml.cs @@ -4,7 +4,7 @@ using Duende.IdentityServer.Events; using Duende.IdentityServer.Extensions; using Duende.IdentityServer.Services; -using IdentityModel; +using Duende.IdentityModel; using IdentityServerHost.Models; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; diff --git a/templates/src/IdentityServerAspNetIdentity/Pages/Consent/Index.cshtml.cs b/templates/src/IdentityServerAspNetIdentity/Pages/Consent/Index.cshtml.cs index e6daedcd7..203d4e7dc 100644 --- a/templates/src/IdentityServerAspNetIdentity/Pages/Consent/Index.cshtml.cs +++ b/templates/src/IdentityServerAspNetIdentity/Pages/Consent/Index.cshtml.cs @@ -6,7 +6,7 @@ using Duende.IdentityServer.Models; using Duende.IdentityServer.Services; using Duende.IdentityServer.Validation; -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; diff --git a/templates/src/IdentityServerAspNetIdentity/Pages/Diagnostics/ViewModel.cs b/templates/src/IdentityServerAspNetIdentity/Pages/Diagnostics/ViewModel.cs index 174cde047..1ec4f20eb 100644 --- a/templates/src/IdentityServerAspNetIdentity/Pages/Diagnostics/ViewModel.cs +++ b/templates/src/IdentityServerAspNetIdentity/Pages/Diagnostics/ViewModel.cs @@ -1,7 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; using System.Text; using System.Text.Json; diff --git a/templates/src/IdentityServerAspNetIdentity/Pages/ExternalLogin/Callback.cshtml.cs b/templates/src/IdentityServerAspNetIdentity/Pages/ExternalLogin/Callback.cshtml.cs index 695137710..0a5fde7a9 100644 --- a/templates/src/IdentityServerAspNetIdentity/Pages/ExternalLogin/Callback.cshtml.cs +++ b/templates/src/IdentityServerAspNetIdentity/Pages/ExternalLogin/Callback.cshtml.cs @@ -5,7 +5,7 @@ using Duende.IdentityServer; using Duende.IdentityServer.Events; using Duende.IdentityServer.Services; -using IdentityModel; +using Duende.IdentityModel; using IdentityServerHost.Models; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; diff --git a/templates/src/IdentityServerAspNetIdentity/Program.cs b/templates/src/IdentityServerAspNetIdentity/Program.cs index b44278eb3..4b7f936a7 100644 --- a/templates/src/IdentityServerAspNetIdentity/Program.cs +++ b/templates/src/IdentityServerAspNetIdentity/Program.cs @@ -1,5 +1,8 @@ -using IdentityServerAspNetIdentity; +using Duende.IdentityServer.Licensing; +using IdentityServerAspNetIdentity; using Serilog; +using System.Globalization; +using System.Text; Log.Logger = new LoggerConfiguration() .WriteTo.Console() @@ -30,6 +33,16 @@ return; } + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } + app.Run(); } catch (Exception ex) when (ex is not HostAbortedException) @@ -40,4 +53,17 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} + +static string Summary(LicenseUsageSummary usage) +{ + var sb = new StringBuilder(); + sb.AppendLine("IdentityServer Usage Summary:"); + sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}"); + var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None"; + sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used"); + + return sb.ToString(); +} diff --git a/templates/src/IdentityServerAspNetIdentity/SeedData.cs b/templates/src/IdentityServerAspNetIdentity/SeedData.cs index 06d32415b..918a6a3dd 100644 --- a/templates/src/IdentityServerAspNetIdentity/SeedData.cs +++ b/templates/src/IdentityServerAspNetIdentity/SeedData.cs @@ -1,5 +1,5 @@ using System.Security.Claims; -using IdentityModel; +using Duende.IdentityModel; using IdentityServerAspNetIdentity.Data; using IdentityServerHost.Models; using Microsoft.AspNetCore.Identity; diff --git a/templates/src/IdentityServerEmpty/IdentityServerEmpty.csproj b/templates/src/IdentityServerEmpty/IdentityServerEmpty.csproj index f3359f59d..648511680 100644 --- a/templates/src/IdentityServerEmpty/IdentityServerEmpty.csproj +++ b/templates/src/IdentityServerEmpty/IdentityServerEmpty.csproj @@ -7,8 +7,8 @@ - + - + diff --git a/templates/src/IdentityServerEmpty/Program.cs b/templates/src/IdentityServerEmpty/Program.cs index a25ba961d..f8a2a4504 100644 --- a/templates/src/IdentityServerEmpty/Program.cs +++ b/templates/src/IdentityServerEmpty/Program.cs @@ -1,5 +1,8 @@ -using IdentityServerEmpty; +using Duende.IdentityServer.Licensing; +using IdentityServerEmpty; using Serilog; +using System.Globalization; +using System.Text; Log.Logger = new LoggerConfiguration() .WriteTo.Console() @@ -19,7 +22,17 @@ var app = builder .ConfigureServices() .ConfigurePipeline(); - + + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } + app.Run(); } catch (Exception ex) @@ -30,4 +43,17 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} + +static string Summary(LicenseUsageSummary usage) +{ + var sb = new StringBuilder(); + sb.AppendLine("IdentityServer Usage Summary:"); + sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}"); + var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None"; + sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used"); + + return sb.ToString(); +} diff --git a/templates/src/IdentityServerEntityFramework/IdentityServerEntityFramework.csproj b/templates/src/IdentityServerEntityFramework/IdentityServerEntityFramework.csproj index d37f23663..c927b16de 100644 --- a/templates/src/IdentityServerEntityFramework/IdentityServerEntityFramework.csproj +++ b/templates/src/IdentityServerEntityFramework/IdentityServerEntityFramework.csproj @@ -7,14 +7,14 @@ - + - - + + - - - + + + diff --git a/templates/src/IdentityServerEntityFramework/Pages/Account/Logout/Index.cshtml.cs b/templates/src/IdentityServerEntityFramework/Pages/Account/Logout/Index.cshtml.cs index aef1de3d8..61cb4e6c4 100644 --- a/templates/src/IdentityServerEntityFramework/Pages/Account/Logout/Index.cshtml.cs +++ b/templates/src/IdentityServerEntityFramework/Pages/Account/Logout/Index.cshtml.cs @@ -4,7 +4,7 @@ using Duende.IdentityServer.Events; using Duende.IdentityServer.Extensions; using Duende.IdentityServer.Services; -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/templates/src/IdentityServerEntityFramework/Pages/Admin/Clients/New.cshtml.cs b/templates/src/IdentityServerEntityFramework/Pages/Admin/Clients/New.cshtml.cs index eb5920448..f7c2f906c 100644 --- a/templates/src/IdentityServerEntityFramework/Pages/Admin/Clients/New.cshtml.cs +++ b/templates/src/IdentityServerEntityFramework/Pages/Admin/Clients/New.cshtml.cs @@ -1,7 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; diff --git a/templates/src/IdentityServerEntityFramework/Pages/Consent/Index.cshtml.cs b/templates/src/IdentityServerEntityFramework/Pages/Consent/Index.cshtml.cs index e6daedcd7..203d4e7dc 100644 --- a/templates/src/IdentityServerEntityFramework/Pages/Consent/Index.cshtml.cs +++ b/templates/src/IdentityServerEntityFramework/Pages/Consent/Index.cshtml.cs @@ -6,7 +6,7 @@ using Duende.IdentityServer.Models; using Duende.IdentityServer.Services; using Duende.IdentityServer.Validation; -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; diff --git a/templates/src/IdentityServerEntityFramework/Pages/Diagnostics/ViewModel.cs b/templates/src/IdentityServerEntityFramework/Pages/Diagnostics/ViewModel.cs index 174cde047..1ec4f20eb 100644 --- a/templates/src/IdentityServerEntityFramework/Pages/Diagnostics/ViewModel.cs +++ b/templates/src/IdentityServerEntityFramework/Pages/Diagnostics/ViewModel.cs @@ -1,7 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; using System.Text; using System.Text.Json; diff --git a/templates/src/IdentityServerEntityFramework/Pages/ExternalLogin/Callback.cshtml.cs b/templates/src/IdentityServerEntityFramework/Pages/ExternalLogin/Callback.cshtml.cs index fb70ec8f2..9635416d1 100644 --- a/templates/src/IdentityServerEntityFramework/Pages/ExternalLogin/Callback.cshtml.cs +++ b/templates/src/IdentityServerEntityFramework/Pages/ExternalLogin/Callback.cshtml.cs @@ -6,7 +6,7 @@ using Duende.IdentityServer.Events; using Duende.IdentityServer.Services; using Duende.IdentityServer.Test; -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/templates/src/IdentityServerEntityFramework/Pages/TestUsers.cs b/templates/src/IdentityServerEntityFramework/Pages/TestUsers.cs index 1bf95201f..4fc69922b 100644 --- a/templates/src/IdentityServerEntityFramework/Pages/TestUsers.cs +++ b/templates/src/IdentityServerEntityFramework/Pages/TestUsers.cs @@ -1,7 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. -using IdentityModel; +using Duende.IdentityModel; using System.Security.Claims; using System.Text.Json; using Duende.IdentityServer; diff --git a/templates/src/IdentityServerEntityFramework/Program.cs b/templates/src/IdentityServerEntityFramework/Program.cs index c44ba7029..f6005b22c 100644 --- a/templates/src/IdentityServerEntityFramework/Program.cs +++ b/templates/src/IdentityServerEntityFramework/Program.cs @@ -1,5 +1,8 @@ -using IdentityServerEntityFramework; +using Duende.IdentityServer.Licensing; +using IdentityServerEntityFramework; using Serilog; +using System.Globalization; +using System.Text; Log.Logger = new LoggerConfiguration() .WriteTo.Console() @@ -30,6 +33,16 @@ return; } + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } + app.Run(); } catch (Exception ex) when (ex is not HostAbortedException) @@ -40,4 +53,17 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} + +static string Summary(LicenseUsageSummary usage) +{ + var sb = new StringBuilder(); + sb.AppendLine("IdentityServer Usage Summary:"); + sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}"); + var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None"; + sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used"); + + return sb.ToString(); +} diff --git a/templates/src/IdentityServerInMem/IdentityServerInMem.csproj b/templates/src/IdentityServerInMem/IdentityServerInMem.csproj index 19c78a357..e7dfdb392 100644 --- a/templates/src/IdentityServerInMem/IdentityServerInMem.csproj +++ b/templates/src/IdentityServerInMem/IdentityServerInMem.csproj @@ -7,10 +7,10 @@ - + - - + + diff --git a/templates/src/IdentityServerInMem/Pages/Account/Logout/Index.cshtml.cs b/templates/src/IdentityServerInMem/Pages/Account/Logout/Index.cshtml.cs index aef1de3d8..61cb4e6c4 100644 --- a/templates/src/IdentityServerInMem/Pages/Account/Logout/Index.cshtml.cs +++ b/templates/src/IdentityServerInMem/Pages/Account/Logout/Index.cshtml.cs @@ -4,7 +4,7 @@ using Duende.IdentityServer.Events; using Duende.IdentityServer.Extensions; using Duende.IdentityServer.Services; -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/templates/src/IdentityServerInMem/Pages/Consent/Index.cshtml.cs b/templates/src/IdentityServerInMem/Pages/Consent/Index.cshtml.cs index e6daedcd7..203d4e7dc 100644 --- a/templates/src/IdentityServerInMem/Pages/Consent/Index.cshtml.cs +++ b/templates/src/IdentityServerInMem/Pages/Consent/Index.cshtml.cs @@ -6,7 +6,7 @@ using Duende.IdentityServer.Models; using Duende.IdentityServer.Services; using Duende.IdentityServer.Validation; -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; diff --git a/templates/src/IdentityServerInMem/Pages/Diagnostics/ViewModel.cs b/templates/src/IdentityServerInMem/Pages/Diagnostics/ViewModel.cs index 174cde047..1ec4f20eb 100644 --- a/templates/src/IdentityServerInMem/Pages/Diagnostics/ViewModel.cs +++ b/templates/src/IdentityServerInMem/Pages/Diagnostics/ViewModel.cs @@ -1,7 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; using System.Text; using System.Text.Json; diff --git a/templates/src/IdentityServerInMem/Pages/ExternalLogin/Callback.cshtml.cs b/templates/src/IdentityServerInMem/Pages/ExternalLogin/Callback.cshtml.cs index fb70ec8f2..9635416d1 100644 --- a/templates/src/IdentityServerInMem/Pages/ExternalLogin/Callback.cshtml.cs +++ b/templates/src/IdentityServerInMem/Pages/ExternalLogin/Callback.cshtml.cs @@ -6,7 +6,7 @@ using Duende.IdentityServer.Events; using Duende.IdentityServer.Services; using Duende.IdentityServer.Test; -using IdentityModel; +using Duende.IdentityModel; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/templates/src/IdentityServerInMem/Pages/TestUsers.cs b/templates/src/IdentityServerInMem/Pages/TestUsers.cs index 1bf95201f..4fc69922b 100644 --- a/templates/src/IdentityServerInMem/Pages/TestUsers.cs +++ b/templates/src/IdentityServerInMem/Pages/TestUsers.cs @@ -1,7 +1,7 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. -using IdentityModel; +using Duende.IdentityModel; using System.Security.Claims; using System.Text.Json; using Duende.IdentityServer; diff --git a/templates/src/IdentityServerInMem/Program.cs b/templates/src/IdentityServerInMem/Program.cs index 6d2944f6b..7a4e47324 100644 --- a/templates/src/IdentityServerInMem/Program.cs +++ b/templates/src/IdentityServerInMem/Program.cs @@ -1,5 +1,8 @@ -using IdentityServerInMem; +using Duende.IdentityServer.Licensing; +using IdentityServerInMem; using Serilog; +using System.Globalization; +using System.Text; Log.Logger = new LoggerConfiguration() .WriteTo.Console() @@ -19,7 +22,17 @@ var app = builder .ConfigureServices() .ConfigurePipeline(); - + + if (app.Environment.IsDevelopment()) + { + app.Lifetime.ApplicationStopping.Register(() => + { + var usage = app.Services.GetRequiredService(); + Console.Write(Summary(usage)); + Console.ReadKey(); + }); + } + app.Run(); } catch (Exception ex) @@ -30,4 +43,17 @@ { Log.Information("Shut down complete"); Log.CloseAndFlush(); -} \ No newline at end of file +} + +static string Summary(LicenseUsageSummary usage) +{ + var sb = new StringBuilder(); + sb.AppendLine("IdentityServer Usage Summary:"); + sb.AppendLine(CultureInfo.InvariantCulture, $" License: {usage.LicenseEdition}"); + var features = usage.FeaturesUsed.Count > 0 ? string.Join(", ", usage.FeaturesUsed) : "None"; + sb.AppendLine(CultureInfo.InvariantCulture, $" Business and Enterprise Edition Features Used: {features}"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.ClientsUsed.Count} Client Id(s) Used"); + sb.AppendLine(CultureInfo.InvariantCulture, $" {usage.IssuersUsed.Count} Issuer(s) Used"); + + return sb.ToString(); +}