Compare commits

...

6 Commits

2 changed files with 19 additions and 2 deletions
+18 -2
View File
@@ -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,8 +53,21 @@ 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)
{ {
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()
.PersistKeysToFileSystem(new DirectoryInfo(keysFolderPath))
.SetApplicationName("MidrandBookshop");
var configSection = configuration.GetSection(nameof(LiteCharmsSettings)); var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
var authOptions = new LiteCharmsSettings(); var authOptions = new LiteCharmsSettings();
@@ -77,6 +92,8 @@ public static class Api
options.SaveTokens = true; options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true; options.GetClaimsFromUserInfoEndpoint = true;
options.ForwardSignOut = CookieAuthenticationDefaults.AuthenticationScheme;
options.Scope.Clear(); options.Scope.Clear();
options.Scope.Add("openid"); options.Scope.Add("openid");
options.Scope.Add("profile"); options.Scope.Add("profile");
@@ -159,7 +176,6 @@ public static class Api
authProperties.Parameters.Add("id_token_hint", idToken); authProperties.Parameters.Add("id_token_hint", idToken);
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, authProperties); await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, authProperties);
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}); });
return app; return app;
@@ -194,6 +194,7 @@
<!-- Shared Usings --> <!-- Shared Usings -->
<ItemGroup> <ItemGroup>
<Using Include="Microsoft.AspNetCore.DataProtection" />
<Using Include="Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage" /> <Using Include="Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage" />
<Using Include="System.Text.Json.Serialization" /> <Using Include="System.Text.Json.Serialization" />
<Using Include="System.Reflection" /> <Using Include="System.Reflection" />