Skip to content

Commit 8f4967a

Browse files
Ticket #784 : Persist DataProtection (Admin Website)
1 parent c79eebc commit 8f4967a

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/IdServer/SimpleIdServer.IdServer.Website.Startup/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Microsoft.AspNetCore.DataProtection;
2+
13
var builder = WebApplication.CreateBuilder(args);
24

35
// Add services to the container.
@@ -6,12 +8,19 @@
68
.AddEnvironmentVariables();
79
builder.Services.AddRazorPages();
810
builder.Services.AddServerSideBlazor();
11+
var dataProtectionPath = builder.Configuration["dataProtectionPath"]?.ToString();
912
var isRealmEnabled = bool.Parse(builder.Configuration["IsRealmEnabled"]);
1013
builder.Services.AddSIDWebsite(o =>
1114
{
1215
o.IdServerBaseUrl = builder.Configuration["IdServerBaseUrl"];
1316
o.SCIMUrl = builder.Configuration["ScimBaseUrl"];
1417
o.IsReamEnabled = isRealmEnabled;
18+
}, (c) =>
19+
{
20+
if(!string.IsNullOrWhiteSpace(dataProtectionPath))
21+
{
22+
c.PersistKeysToFileSystem(new DirectoryInfo(dataProtectionPath));
23+
}
1524
});
1625
bool forceHttps = false;
1726
var forceHttpsStr = builder.Configuration["forceHttps"];

src/IdServer/SimpleIdServer.IdServer.Website/ServiceCollectionExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Authentication;
55
using Microsoft.AspNetCore.Authentication.Cookies;
66
using Microsoft.AspNetCore.Authorization;
7+
using Microsoft.AspNetCore.DataProtection;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.Extensions.Configuration;
910
using Microsoft.IdentityModel.Tokens;
@@ -20,7 +21,7 @@ namespace Microsoft.Extensions.DependencyInjection
2021
{
2122
public static class ServiceCollectionExtensions
2223
{
23-
public static IServiceCollection AddSIDWebsite(this IServiceCollection services, Action<IdServerWebsiteOptions>? callbackOptions = null)
24+
public static IServiceCollection AddSIDWebsite(this IServiceCollection services, Action<IdServerWebsiteOptions>? callbackOptions = null, Action<IDataProtectionBuilder>? dataProtectionBuilderCallback = null)
2425
{
2526
var opts = new IdServerWebsiteOptions();
2627
if (callbackOptions != null) callbackOptions(opts);
@@ -44,6 +45,8 @@ public static IServiceCollection AddSIDWebsite(this IServiceCollection services,
4445
services.AddSingleton<IWebsiteHttpClientFactory, WebsiteHttpClientFactory>();
4546
if (callbackOptions == null) services.Configure<IdServerWebsiteOptions>((o) => { });
4647
else services.Configure(callbackOptions);
48+
var b = services.AddDataProtection();
49+
if (dataProtectionBuilderCallback != null) dataProtectionBuilderCallback(b);
4750
return services;
4851
}
4952

0 commit comments

Comments
 (0)