From 67f31775ec6e05664324d7102b4761e2e64d88c3 Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Sat, 14 Dec 2024 14:28:56 +0100 Subject: [PATCH 1/2] Move authentication token registration to shared kernel --- .../account-management/Core/Configuration.cs | 8 -------- .../Configuration/SharedDependencyConfiguration.cs | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/application/account-management/Core/Configuration.cs b/application/account-management/Core/Configuration.cs index 88e3a7967..0b448f411 100644 --- a/application/account-management/Core/Configuration.cs +++ b/application/account-management/Core/Configuration.cs @@ -1,11 +1,8 @@ -using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using PlatformPlatform.AccountManagement.Database; using PlatformPlatform.AccountManagement.Features.Users.Shared; using PlatformPlatform.AccountManagement.Integrations.Gravatar; -using PlatformPlatform.SharedKernel.Authentication; -using PlatformPlatform.SharedKernel.Authentication.TokenGeneration; using PlatformPlatform.SharedKernel.Configuration; namespace PlatformPlatform.AccountManagement; @@ -28,11 +25,6 @@ public static IServiceCollection AddAccountManagementServices(this IServiceColle return services .AddSharedServices(Assembly) - .AddScoped, PasswordHasher>() - .AddScoped() - .AddScoped() - .AddScoped() - .AddScoped() .AddScoped() .AddScoped(); } diff --git a/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs b/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs index 593c56714..1cd4b0c29 100644 --- a/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs +++ b/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs @@ -4,9 +4,12 @@ using Azure.Security.KeyVault.Secrets; using FluentValidation; using Microsoft.AspNetCore.Http.Json; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; +using PlatformPlatform.SharedKernel.Authentication; +using PlatformPlatform.SharedKernel.Authentication.TokenGeneration; using PlatformPlatform.SharedKernel.Authentication.TokenSigning; using PlatformPlatform.SharedKernel.DomainEvents; using PlatformPlatform.SharedKernel.Integrations.Email; @@ -36,6 +39,7 @@ public static IServiceCollection AddSharedServices(this IServiceCollection se return services .AddServiceDiscovery() .AddSingleton(GetTokenSigningService()) + .AddAuthentication() .AddDefaultJsonSerializerOptions() .AddPersistenceHelpers() .AddDefaultHealthChecks() @@ -66,6 +70,16 @@ public static ITokenSigningClient GetTokenSigningService() return new DevelopmentTokenSigningClient(); } + private static IServiceCollection AddAuthentication(this IServiceCollection services) + { + return services + .AddScoped, PasswordHasher>() + .AddScoped() + .AddScoped() + .AddScoped() + .AddScoped(); + } + private static IServiceCollection AddDefaultJsonSerializerOptions(this IServiceCollection services) { return services.Configure(options => From 4275e5cfd8f2d4f74068a849f8c2d1d92851773b Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Sat, 14 Dec 2024 14:29:23 +0100 Subject: [PATCH 2/2] Rename AddEmailSignatureClient to AddEmailClient --- .../Configuration/SharedDependencyConfiguration.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs b/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs index 1cd4b0c29..37d89916b 100644 --- a/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs +++ b/application/shared-kernel/SharedKernel/Configuration/SharedDependencyConfiguration.cs @@ -43,7 +43,7 @@ public static IServiceCollection AddSharedServices(this IServiceCollection se .AddDefaultJsonSerializerOptions() .AddPersistenceHelpers() .AddDefaultHealthChecks() - .AddEmailSignatureClient() + .AddEmailClient() .AddMediatRPipelineBehaviours() .RegisterMediatRRequest(assemblies) .RegisterRepositories(assemblies); @@ -111,7 +111,7 @@ private static IServiceCollection AddDefaultHealthChecks(this IServiceCollection return services; } - private static IServiceCollection AddEmailSignatureClient(this IServiceCollection services) + private static IServiceCollection AddEmailClient(this IServiceCollection services) { if (SharedInfrastructureConfiguration.IsRunningInAzure) {