feat(infrastructure): register RsaKeyService in DI
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user