diff --git a/LiteCharms.Features/Extensions/Api.cs b/LiteCharms.Features/Extensions/Api.cs index 96fb0ba..28d2875 100644 --- a/LiteCharms.Features/Extensions/Api.cs +++ b/LiteCharms.Features/Extensions/Api.cs @@ -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));