diff --git a/src/TaxBaik.Web/Program.cs b/src/TaxBaik.Web/Program.cs index 26d7972..dedbfae 100644 --- a/src/TaxBaik.Web/Program.cs +++ b/src/TaxBaik.Web/Program.cs @@ -2,14 +2,12 @@ using System.IO.Compression; using System.Text; using System.Text.Encodings.Web; using System.Text.Unicode; -using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OAuth; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.RateLimiting; using Microsoft.AspNetCore.ResponseCompression; -using Microsoft.IdentityModel.Tokens; using MudBlazor.Services; using Serilog; using FluentValidation; @@ -56,26 +54,7 @@ builder.Host.UseSerilog((context, config) => } }); -// Controllers + FastEndpoints (API-First) -builder.Services.AddControllers(); -builder.Services.AddFastEndpoints(config => -{ - config.Assemblies = new[] { typeof(Program).Assembly }; -}); -// FastEndpoints Authorization Policy -builder.Services.AddAuthorization(opts => -{ - opts.DefaultPolicy = new Microsoft.AspNetCore.Authorization.AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) - .RequireAuthenticatedUser() - .Build(); - opts.AddPolicy("Bearer", new Microsoft.AspNetCore.Authorization.AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) - .RequireAuthenticatedUser() - .Build()); - opts.AddPolicy("AdminOnly", new Microsoft.AspNetCore.Authorization.AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) - .RequireAuthenticatedUser() - .RequireRole("Admin") - .Build()); -}); +builder.Services.AddAuthorization(); builder.Services.AddProblemDetails(); builder.Services.AddHealthChecks(); builder.Services.AddRateLimiter(options => @@ -115,32 +94,14 @@ builder.Services.AddSession(options => builder.Services.AddDistributedMemoryCache(); // TempData는 기본적으로 쿠키 저장소 사용 (위 세션 설정 상속) -// 인증: 관리자 쿠키 + 포털 쿠키 + 기존 JWT(과도기 API) +// 인증: 관리자 쿠키 + 포털 쿠키 var connectionString = builder.Configuration.GetConnectionString("Default") ?? throw new InvalidOperationException("Missing connection string"); -var jwtKey = builder.Configuration["Jwt:SecretKey"] ?? throw new InvalidOperationException("Missing JWT SecretKey"); -if (isProduction && jwtKey.Contains("dev-secret", StringComparison.OrdinalIgnoreCase)) - throw new InvalidOperationException("Production JWT SecretKey must not use the development default."); -var key = Encoding.ASCII.GetBytes(jwtKey); var authenticationBuilder = builder.Services.AddAuthentication(opts => { - opts.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - opts.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; -}) -.AddJwtBearer(opts => -{ - opts.TokenValidationParameters = new TokenValidationParameters - { - ValidateIssuerSigningKey = true, - IssuerSigningKey = new SymmetricSecurityKey(key), - ValidateIssuer = true, - ValidIssuer = "taxbaik-admin", - ValidateAudience = true, - ValidAudience = "taxbaik-admin-client", - ValidateLifetime = true, - ClockSkew = TimeSpan.FromMinutes(1) - }; + opts.DefaultAuthenticateScheme = PortalAuthDefaults.Scheme; + opts.DefaultChallengeScheme = PortalAuthDefaults.Scheme; }) .AddCookie(PortalAuthDefaults.Scheme, opts => { @@ -172,6 +133,8 @@ var authenticationBuilder = builder.Services.AddAuthentication(opts => opts.Cookie.SecurePolicy = isProduction ? CookieSecurePolicy.Always : CookieSecurePolicy.SameAsRequest; }); +builder.Services.AddAuthorization(); + var googleClientId = builder.Configuration["Authentication:Google:ClientId"]; var googleClientSecret = builder.Configuration["Authentication:Google:ClientSecret"]; if (!string.IsNullOrWhiteSpace(googleClientId) && !string.IsNullOrWhiteSpace(googleClientSecret))