Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Add new secutiry settings KeyPersistenceLocation (#261)

Krzysztof Pajak2a19dea4bd90
diff --git a/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs b/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs
index 484641483..0458ff729 100644
--- a/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs
+++ b/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs
@@ -12,6 +12,10 @@
/// </summary>
public string AllowedHosts { get; set; }
+ /// <summary>
+ /// Gets or sets a value for Key persistence location
+ /// </summary>
+ public string KeyPersistenceLocation { get; set; }
/// <summary>
/// Gets or sets a value indicating for cookie expires in hours - default 24 * 365 = 8760
/// </summary>
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index 3a744e5ca..b06c6a7ad 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -130,8 +130,12 @@ namespace Grand.Web.Common.Infrastructure
}
else
{
- var dataProtectionKeysPath = CommonPath.DataProtectionKeysPath;
+ var securityconfig = new SecurityConfig();
+ configuration.GetSection("Security").Bind(securityconfig);
+
+ var dataProtectionKeysPath = string.IsNullOrEmpty(securityconfig.KeyPersistenceLocation) ? CommonPath.DataProtectionKeysPath : securityconfig.KeyPersistenceLocation;
var dataProtectionKeysFolder = new DirectoryInfo(dataProtectionKeysPath);
+
//configure the data protection system to persist keys to the specified directory
services.AddDataProtection().PersistKeysToFileSystem(dataProtectionKeysFolder);
}
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index 29847a5cc..5780f34d8 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -72,6 +72,10 @@
"HttpsRedirectionRedirect": 308,
"HttpsRedirectionHttpsPort": 443,
+ //Key persistence location you can point to a directory on the local machine, or it can point to a folder on a network share.
+ //if is null it will use the default directory path - ApplicationPath\App_Data\DataProtectionKeys
+ "KeyPersistenceLocation": null,
+
//Gets or sets a value indicating for cookie auth expires in hours - default 24 * 365 = 8760
"CookieAuthExpires": 8760,