Refactored AddLiteCharmsWebSecurity to be OS aware when it handles data protection keys #121
@@ -2,6 +2,8 @@
|
||||
using LiteCharms.Features.Api;
|
||||
using LiteCharms.Features.Api.Configuration;
|
||||
using LiteCharms.Features.Api.Sdk;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LiteCharms.Features.Extensions;
|
||||
|
||||
@@ -51,13 +53,20 @@ public static class Api
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration)
|
||||
public static IServiceCollection AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment)
|
||||
{
|
||||
var keysFolder = Path.Combine("/app/shared-keys");
|
||||
string keysFolderPath;
|
||||
|
||||
if (OperatingSystem.IsLinux())
|
||||
keysFolderPath = "/app/shared-keys";
|
||||
else
|
||||
keysFolderPath = Path.Combine(environment.ContentRootPath, "obj", "DeveloperDataProtectionKeys");
|
||||
|
||||
if (!Directory.Exists(keysFolderPath)) Directory.CreateDirectory(keysFolderPath);
|
||||
|
||||
services.AddDataProtection()
|
||||
.PersistKeysToFileSystem(new DirectoryInfo(keysFolder))
|
||||
.SetApplicationName("MidrandBooks");
|
||||
.PersistKeysToFileSystem(new DirectoryInfo(keysFolderPath))
|
||||
.SetApplicationName("MidrandBookshop");
|
||||
|
||||
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user