feat(infrastructure): register RsaKeyService in DI

This commit is contained in:
Joseph Doherty
2026-01-03 08:19:39 -05:00
parent 97ef3e4345
commit 5ae634888f
2 changed files with 35 additions and 6 deletions
@@ -0,0 +1,15 @@
namespace JdeScoping.Core.Options;
/// <summary>
/// Configuration options for RSA key service.
/// </summary>
public class RsaKeyOptions
{
public const string SectionName = "RsaKey";
/// <summary>
/// Path to store the RSA private key file.
/// Defaults to "data/rsa-key.bin" relative to app directory.
/// </summary>
public string KeyFilePath { get; set; } = "data/rsa-key.bin";
}
@@ -1,6 +1,8 @@
using JdeScoping.Core.Interfaces;
using JdeScoping.Core.Options;
using JdeScoping.Infrastructure.Auth;
using JdeScoping.Infrastructure.Options;
using JdeScoping.Infrastructure.Security;
using JdeScoping.Infrastructure.Sources.Cms;
using JdeScoping.Infrastructure.Sources.Jde;
using Microsoft.Extensions.Configuration;
@@ -25,8 +27,6 @@ public static class InfrastructureDependencyInjection
// Bind configuration
services.Configure<DataSourceOptions>(
configuration.GetSection(DataSourceOptions.SectionName));
services.Configure<AuthOptions>(
configuration.GetSection(AuthOptions.SectionName));
services.Configure<LdapOptions>(
configuration.GetSection(LdapOptions.SectionName));
@@ -47,11 +47,11 @@ public static class InfrastructureDependencyInjection
}
// Register auth service based on configuration
var authOptions = configuration
.GetSection(AuthOptions.SectionName)
.Get<AuthOptions>();
var ldapOptions = configuration
.GetSection(LdapOptions.SectionName)
.Get<LdapOptions>();
if (authOptions?.UseFakeAuth == true)
if (ldapOptions?.UseFakeAuth == true)
{
services.AddScoped<IAuthService, FakeAuthService>();
}
@@ -60,6 +60,20 @@ public static class InfrastructureDependencyInjection
services.AddScoped<IAuthService, LdapAuthService>();
}
// Register RSA key service for login encryption
services.Configure<RsaKeyOptions>(
configuration.GetSection(RsaKeyOptions.SectionName));
var rsaKeyOptions = configuration
.GetSection(RsaKeyOptions.SectionName)
.Get<RsaKeyOptions>() ?? new RsaKeyOptions();
var keyPath = Path.IsPathRooted(rsaKeyOptions.KeyFilePath)
? rsaKeyOptions.KeyFilePath
: Path.Combine(AppContext.BaseDirectory, rsaKeyOptions.KeyFilePath);
services.AddSingleton<IRsaKeyService>(new RsaKeyService(keyPath));
return services;
}
}