Skip to content

Commit

Permalink
feat: allow to configure DataProtection
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Jan 31, 2024
1 parent 1610790 commit c6d0ca8
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Sitko.Core.App.Web/SitkoCoreWebApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,17 @@ protected override void BeforeContainerBuild()
});
}

AddDataProtection();
var dataProtectionBuilder = Services.AddDataProtection()
.SetApplicationName(BootApplicationContext.Name)
.SetDefaultKeyLifetime(TimeSpan.FromDays(90));
webOptions.ConfigureDataProtection?.Invoke(dataProtectionBuilder);

ConfigureHealthChecks(Services.AddHealthChecks());
}

protected virtual IHealthChecksBuilder ConfigureHealthChecks(IHealthChecksBuilder healthChecksBuilder) =>
healthChecksBuilder;

private void AddDataProtection() =>
ConfigureDataProtection(Services.AddDataProtection());

protected virtual IDataProtectionBuilder
ConfigureDataProtection(IDataProtectionBuilder dataProtectionBuilder) =>
dataProtectionBuilder
.SetApplicationName(BootApplicationContext.Name)
.SetDefaultKeyLifetime(TimeSpan.FromDays(90));

// https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/
private static void CheckSameSite(HttpContext httpContext, CookieOptions options)
{
Expand Down Expand Up @@ -163,6 +158,8 @@ public class SitkoCoreWebOptions
public bool AllowAllForwardedHeaders { get; set; } = true;
public bool EnableStaticFiles { get; set; } = true;

public Action<IDataProtectionBuilder>? ConfigureDataProtection { get; set; }

public SitkoCoreWebOptions AddCorsPolicy(string name, CorsPolicy policy, bool isDefault = false)
{
if (CorsPolicies.ContainsKey(name))
Expand Down

0 comments on commit c6d0ca8

Please sign in to comment.