Refactored AddLiteCharmsWebSecurity to be OS aware when it handles data protection keys
continuous-integration/drone/pr Build is passing
continuous-integration/drone/pr Build is passing
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
using LiteCharms.Features.Api;
|
using LiteCharms.Features.Api;
|
||||||
using LiteCharms.Features.Api.Configuration;
|
using LiteCharms.Features.Api.Configuration;
|
||||||
using LiteCharms.Features.Api.Sdk;
|
using LiteCharms.Features.Api.Sdk;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace LiteCharms.Features.Extensions;
|
namespace LiteCharms.Features.Extensions;
|
||||||
|
|
||||||
@@ -51,13 +53,20 @@ public static class Api
|
|||||||
return services;
|
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()
|
services.AddDataProtection()
|
||||||
.PersistKeysToFileSystem(new DirectoryInfo(keysFolder))
|
.PersistKeysToFileSystem(new DirectoryInfo(keysFolderPath))
|
||||||
.SetApplicationName("MidrandBooks");
|
.SetApplicationName("MidrandBookshop");
|
||||||
|
|
||||||
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user