diff --git a/src/dotnet/QuantEngine.Web/Program.cs b/src/dotnet/QuantEngine.Web/Program.cs index d807acc..d7179ba 100644 --- a/src/dotnet/QuantEngine.Web/Program.cs +++ b/src/dotnet/QuantEngine.Web/Program.cs @@ -16,6 +16,9 @@ using QuantEngine.Web.Endpoints; using System.Security.Cryptography; using System.Text; using QuantEngine.Core.Models; +using Microsoft.AspNetCore.Authentication; +using System.Text.Encodings.Web; +using Microsoft.Extensions.Options; // Serilog Configuration with Telegram Sink Log.Logger = new LoggerConfiguration() @@ -33,7 +36,8 @@ builder.Services.AddRazorComponents() // Authentication and Custom State Provider (Shared client components) builder.Services.AddCascadingAuthenticationState(); -builder.Services.AddAuthentication(); +builder.Services.AddAuthentication("QuantAdminScheme") + .AddScheme("QuantAdminScheme", _ => { }); builder.Services.AddAuthorization(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -267,3 +271,25 @@ public class LoginRequest public string Password { get; set; } = ""; } +internal sealed class QuantAdminAuthHandler : AuthenticationHandler +{ + public QuantAdminAuthHandler( + IOptionsMonitor options, + ILoggerFactory logger, + UrlEncoder encoder) + : base(options, logger, encoder) + { + } + + protected override Task HandleAuthenticateAsync() + { + return Task.FromResult(AuthenticateResult.NoResult()); + } + + protected override Task HandleChallengeAsync(AuthenticationProperties properties) + { + Response.StatusCode = StatusCodes.Status401Unauthorized; + return Task.CompletedTask; + } +} +