|
|
|
@@ -2,6 +2,8 @@
|
|
|
|
|
using LiteCharms.Features.Api;
|
|
|
|
|
using LiteCharms.Features.Api.Configuration;
|
|
|
|
|
using LiteCharms.Features.Api.Sdk;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace LiteCharms.Features.Extensions;
|
|
|
|
|
|
|
|
|
@@ -51,8 +53,21 @@ public static class Api
|
|
|
|
|
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 authOptions = new LiteCharmsSettings();
|
|
|
|
@@ -77,6 +92,8 @@ public static class Api
|
|
|
|
|
options.SaveTokens = true;
|
|
|
|
|
options.GetClaimsFromUserInfoEndpoint = true;
|
|
|
|
|
|
|
|
|
|
options.ForwardSignOut = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
|
|
|
|
|
|
|
|
options.Scope.Clear();
|
|
|
|
|
options.Scope.Add("openid");
|
|
|
|
|
options.Scope.Add("profile");
|
|
|
|
@@ -159,7 +176,6 @@ public static class Api
|
|
|
|
|
authProperties.Parameters.Add("id_token_hint", idToken);
|
|
|
|
|
|
|
|
|
|
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, authProperties);
|
|
|
|
|
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|