From f9322bed7b7935663ea8cc43a154ed666786ce6d Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 28 Mar 2023 22:19:18 +0200 Subject: [PATCH] Update Oidc client. (#981) * Update Oidc client. * Fix tests * Update assets. --- .../Pipeline/CachingKeysMiddleware.cs | 1 - .../RequestLogPerformanceMiddleware.cs | 43 +++--- .../Config/DynamicApplicationStore.cs | 4 +- backend/src/Squidex/Startup.cs | 1 - .../wwwroot/client-callback-popup.html | 9 +- .../wwwroot/client-callback-silent.html | 9 +- .../wwwroot/scripts/editor-json-schema.html | 2 +- .../wwwroot/scripts/editor-references.html | 2 +- .../wwwroot/scripts/oidc-client-ts.min.js | 2 + .../wwwroot/scripts/oidc-client.min.js | 47 ------ frontend/angular.json | 7 +- frontend/package-lock.json | 72 ++++----- frontend/package.json | 2 +- .../interceptors/auth.interceptor.spec.ts | 58 ++++--- .../shared/interceptors/auth.interceptor.ts | 8 +- .../src/app/shared/services/auth.service.ts | 141 ++++++++---------- .../shell/pages/home/home-page.component.html | 2 +- .../shell/pages/home/home-page.component.ts | 27 ++-- .../shell/pages/login/login-page.component.ts | 18 +-- .../pages/logout/logout-page.component.ts | 18 +-- 20 files changed, 198 insertions(+), 275 deletions(-) create mode 100644 backend/src/Squidex/wwwroot/scripts/oidc-client-ts.min.js delete mode 100644 backend/src/Squidex/wwwroot/scripts/oidc-client.min.js diff --git a/backend/src/Squidex.Web/Pipeline/CachingKeysMiddleware.cs b/backend/src/Squidex.Web/Pipeline/CachingKeysMiddleware.cs index 83675bf2b..2598cec6f 100644 --- a/backend/src/Squidex.Web/Pipeline/CachingKeysMiddleware.cs +++ b/backend/src/Squidex.Web/Pipeline/CachingKeysMiddleware.cs @@ -22,7 +22,6 @@ public sealed class CachingKeysMiddleware { this.cachingOptions = cachingOptions.Value; this.cachingManager = cachingManager; - this.next = next; } diff --git a/backend/src/Squidex.Web/Pipeline/RequestLogPerformanceMiddleware.cs b/backend/src/Squidex.Web/Pipeline/RequestLogPerformanceMiddleware.cs index eba1e9c56..58a3ee789 100644 --- a/backend/src/Squidex.Web/Pipeline/RequestLogPerformanceMiddleware.cs +++ b/backend/src/Squidex.Web/Pipeline/RequestLogPerformanceMiddleware.cs @@ -15,42 +15,37 @@ namespace Squidex.Web.Pipeline; public sealed class RequestLogPerformanceMiddleware { - private readonly RequestLogOptions requestLogOptions; private readonly RequestDelegate next; - public RequestLogPerformanceMiddleware(RequestDelegate next, IOptions requestLogOptions) + public RequestLogPerformanceMiddleware(RequestDelegate next) { - this.requestLogOptions = requestLogOptions.Value; - this.next = next; } - public async Task InvokeAsync(HttpContext context, ISemanticLog log) + public async Task InvokeAsync(HttpContext context, ISemanticLog log, IOptions requestLogOptions) { - if (requestLogOptions.LogRequests) + if (!requestLogOptions.Value.LogRequests) { - var watch = ValueStopwatch.StartNew(); - - try - { - await next(context); - } - finally - { - var elapsedMs = watch.Stop(); - - log.LogInformation((elapsedMs, context), (ctx, w) => - { - w.WriteProperty("message", "HTTP request executed."); - w.WriteProperty("elapsedRequestMs", ctx.elapsedMs); - w.WriteObject("filters", ctx.context, LogFilters); - }); - } + await next(context); + return; } - else + + var watch = ValueStopwatch.StartNew(); + try { await next(context); } + finally + { + var elapsedMs = watch.Stop(); + + log.LogInformation((elapsedMs, context), (ctx, w) => + { + w.WriteProperty("message", "HTTP request executed."); + w.WriteProperty("elapsedRequestMs", ctx.elapsedMs); + w.WriteObject("filters", ctx.context, LogFilters); + }); + } } private static void LogFilters(HttpContext httpContext, IObjectWriter obj) diff --git a/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs b/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs index 10f0b79e2..0a5bb1395 100644 --- a/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs +++ b/backend/src/Squidex/Areas/IdentityServer/Config/DynamicApplicationStore.cs @@ -140,8 +140,6 @@ public class DynamicApplicationStore : InMemoryApplicationStore private static IEnumerable<(string, OpenIddictApplicationDescriptor)> CreateStaticClients(IServiceProvider serviceProvider) { - var identityOptions = serviceProvider.GetRequiredService>().Value; - var urlGenerator = serviceProvider.GetRequiredService(); var frontendId = Constants.ClientFrontendId; @@ -207,6 +205,8 @@ public class DynamicApplicationStore : InMemoryApplicationStore Type = ClientTypes.Public }); + var identityOptions = serviceProvider.GetRequiredService>().Value; + if (!identityOptions.IsAdminClientConfigured()) { yield break; diff --git a/backend/src/Squidex/Startup.cs b/backend/src/Squidex/Startup.cs index 49aec6494..eab60729b 100644 --- a/backend/src/Squidex/Startup.cs +++ b/backend/src/Squidex/Startup.cs @@ -123,7 +123,6 @@ public sealed class Startup }); app.UseFrontend(); - app.UsePlugins(); } } diff --git a/backend/src/Squidex/wwwroot/client-callback-popup.html b/backend/src/Squidex/wwwroot/client-callback-popup.html index b9facddf6..836ae241c 100644 --- a/backend/src/Squidex/wwwroot/client-callback-popup.html +++ b/backend/src/Squidex/wwwroot/client-callback-popup.html @@ -4,12 +4,13 @@ - + diff --git a/backend/src/Squidex/wwwroot/client-callback-silent.html b/backend/src/Squidex/wwwroot/client-callback-silent.html index bbb62d06a..96e6d47be 100644 --- a/backend/src/Squidex/wwwroot/client-callback-silent.html +++ b/backend/src/Squidex/wwwroot/client-callback-silent.html @@ -4,12 +4,13 @@ - + diff --git a/backend/src/Squidex/wwwroot/scripts/editor-json-schema.html b/backend/src/Squidex/wwwroot/scripts/editor-json-schema.html index 738423232..874e6b458 100644 --- a/backend/src/Squidex/wwwroot/scripts/editor-json-schema.html +++ b/backend/src/Squidex/wwwroot/scripts/editor-json-schema.html @@ -10,7 +10,7 @@ - +