|
|
|
@@ -3,8 +3,6 @@ using LiteCharms.Features.Api;
|
|
|
|
|
using LiteCharms.Features.Api.Configuration;
|
|
|
|
|
using LiteCharms.Features.Api.Sdk;
|
|
|
|
|
using LiteCharms.Features.Postgres;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace LiteCharms.Features.Extensions;
|
|
|
|
|
|
|
|
|
@@ -56,7 +54,10 @@ public static class Api
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
var certificate = X509CertificateLoader.LoadPkcs12(Convert.FromBase64String(configuration["DataProtection:Certificate"]!), configuration["DataProtection:Password"]);
|
|
|
|
|
|
|
|
|
|
services.AddDataProtection().PersistKeysToDbContext<DataProtectionDbContext>()
|
|
|
|
|
.ProtectKeysWithCertificate(certificate)
|
|
|
|
|
.SetApplicationName("LiteCharmsApp");
|
|
|
|
|
|
|
|
|
|
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
|
|
|
@@ -71,17 +72,26 @@ public static class Api
|
|
|
|
|
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
|
|
|
|
|
})
|
|
|
|
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
|
|
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
|
|
|
|
|
{
|
|
|
|
|
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
|
|
|
|
|
options.Cookie.SameSite = SameSiteMode.Lax;
|
|
|
|
|
options.Cookie.Name = "LiteCharmsApp.Session";
|
|
|
|
|
})
|
|
|
|
|
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
|
|
|
|
|
{
|
|
|
|
|
options.Authority = authOptions.Authority;
|
|
|
|
|
|
|
|
|
|
options.ClientId = authOptions.ClientId;
|
|
|
|
|
options.ClientSecret = authOptions.ClientSecret;
|
|
|
|
|
options.ResponseType = "code";
|
|
|
|
|
|
|
|
|
|
options.SaveTokens = true;
|
|
|
|
|
options.GetClaimsFromUserInfoEndpoint = true;
|
|
|
|
|
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
|
|
|
|
|
options.CorrelationCookie.SameSite = SameSiteMode.None;
|
|
|
|
|
|
|
|
|
|
options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
|
|
|
|
|
options.NonceCookie.SameSite = SameSiteMode.None;
|
|
|
|
|
|
|
|
|
|
options.ForwardSignOut = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
|
|
|
|
|
|
|
|