use filesystem-xml-repository as default for data-protection
This commit is contained in:
@@ -15,6 +15,7 @@ internal class FinchConfigurationModule : FinchModule
|
|||||||
opts.ServiceProvider = svc;
|
opts.ServiceProvider = svc;
|
||||||
opts.Version = "1.0.0-alpha.1";
|
opts.Version = "1.0.0-alpha.1";
|
||||||
opts.TokenExpiration = TimeSpan.FromHours(3);
|
opts.TokenExpiration = TimeSpan.FromHours(3);
|
||||||
|
opts.DataProtectionStoragePath = "../cache/dpkeys";
|
||||||
}).Bind(configuration.GetSection("Finch"));
|
}).Bind(configuration.GetSection("Finch"));
|
||||||
|
|
||||||
services.AddTransient<IFinchOptions, FinchOptions>(factory => factory.GetService<IOptions<FinchOptions>>().Value);
|
services.AddTransient<IFinchOptions, FinchOptions>(factory => factory.GetService<IOptions<FinchOptions>>().Value);
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public class FinchOptions : IFinchOptions
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public TimeSpan TokenExpiration { get; set; }
|
public TimeSpan TokenExpiration { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string DataProtectionStoragePath { get; set; }
|
||||||
|
|
||||||
|
|
||||||
internal IServiceProvider ServiceProvider { get; set; }
|
internal IServiceProvider ServiceProvider { get; set; }
|
||||||
|
|
||||||
@@ -55,7 +58,7 @@ public interface IFinchOptions
|
|||||||
public string Language { get; set; }
|
public string Language { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of the app (used in logging and otehr areas)
|
/// Name of the app (used in logging and other areas)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AppName { get; set; }
|
public string AppName { get; set; }
|
||||||
|
|
||||||
@@ -64,6 +67,11 @@ public interface IFinchOptions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
TimeSpan TokenExpiration { get; set; }
|
TimeSpan TokenExpiration { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path to data protection key storage, when the keys are persisted to the filesystem
|
||||||
|
/// </summary>
|
||||||
|
string DataProtectionStoragePath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get typed options (proxy to IOptions<TOptions>)
|
/// Get typed options (proxy to IOptions<TOptions>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
+2
-2
@@ -14,10 +14,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="10.0.5" />
|
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="10.0.7" />
|
||||||
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
||||||
<PackageReference Include="Postmark" Version="5.3.0" />
|
<PackageReference Include="Postmark" Version="5.3.0" />
|
||||||
<PackageReference Include="PowCapServer.Core" Version="2.0.0" />
|
<PackageReference Include="PowCapServer.Core" Version="2.0.1" />
|
||||||
<PackageReference Include="Seq.Extensions.Logging" Version="9.0.0" />
|
<PackageReference Include="Seq.Extensions.Logging" Version="9.0.0" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.2.0" />
|
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class LogLevelOverrides : Dictionary<string, LogLevel>
|
|||||||
this["Quartz"] = LogLevel.Warning;
|
this["Quartz"] = LogLevel.Warning;
|
||||||
this["Microsoft.AspNetCore"] = LogLevel.Warning;
|
this["Microsoft.AspNetCore"] = LogLevel.Warning;
|
||||||
this["System.Net.Http.HttpClient"] = LogLevel.Warning;
|
this["System.Net.Http.HttpClient"] = LogLevel.Warning;
|
||||||
|
this["Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager"] = LogLevel.Error;
|
||||||
|
|
||||||
string executingAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;
|
string executingAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;
|
||||||
if (executingAssemblyName != null)
|
if (executingAssemblyName != null)
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using System.IO;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||||
|
using Microsoft.AspNetCore.DataProtection.Repositories;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using PowCapServer;
|
using PowCapServer;
|
||||||
using PowCapServer.Abstractions;
|
using PowCapServer.Abstractions;
|
||||||
|
|
||||||
@@ -19,19 +27,24 @@ internal class FinchSecurityModule : FinchModule
|
|||||||
services.TryAddTransient<ISerializer, DefaultSerializer>();
|
services.TryAddTransient<ISerializer, DefaultSerializer>();
|
||||||
services.Configure<PowCapServerOptions>(opts => opts.Default = captchaSection.Get<CaptchaOptions>() ?? new CaptchaOptions());
|
services.Configure<PowCapServerOptions>(opts => opts.Default = captchaSection.Get<CaptchaOptions>() ?? new CaptchaOptions());
|
||||||
services.AddOptions<CaptchaOptions>().Bind(captchaSection);
|
services.AddOptions<CaptchaOptions>().Bind(captchaSection);
|
||||||
|
|
||||||
|
services.AddDataProtection();
|
||||||
|
services.AddSingleton<IConfigureOptions<KeyManagementOptions>>(s =>
|
||||||
|
{
|
||||||
|
ILoggerFactory loggerFactory = s.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance;
|
||||||
|
FinchOptions finchOptions = s.GetService<IOptions<FinchOptions>>().Value;
|
||||||
|
string contentRootPath = s.GetService<IHostEnvironment>().ContentRootPath;
|
||||||
|
|
||||||
|
return new ConfigureOptions<KeyManagementOptions>(options =>
|
||||||
|
{
|
||||||
|
string keyPath = Path.GetFullPath(Path.Combine(contentRootPath, finchOptions.DataProtectionStoragePath));
|
||||||
|
options.XmlRepository = new FileSystemXmlRepository(new DirectoryInfo(keyPath), loggerFactory);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
|
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
// if (app is WebApplication webApp)
|
|
||||||
// {
|
|
||||||
// webApp.MapGet("/teamup/sync", async (ISchedulerFactory scheduler) =>
|
|
||||||
// {
|
|
||||||
// await SyncTeamUpDataJob.RunNow(scheduler);
|
|
||||||
// return "done";
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
StaticCaptchaService.Configure(serviceProvider);
|
StaticCaptchaService.Configure(serviceProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user