diff --git a/src/Fengling.Member.Web/Program.cs b/src/Fengling.Member.Web/Program.cs index a5a373b..40e5fa0 100644 --- a/src/Fengling.Member.Web/Program.cs +++ b/src/Fengling.Member.Web/Program.cs @@ -57,30 +57,30 @@ try builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - - - + + #region 身份认证 var redis = await ConnectionMultiplexer.ConnectAsync(builder.Configuration.GetConnectionString("Redis")!); builder.Services.AddSingleton(_ => redis); - + // DataProtection - use custom extension that resolves IConnectionMultiplexer from DI builder.Services.AddDataProtection() .PersistKeysToStackExchangeRedis("DataProtection-Keys"); - // 配置JWT认证 - builder.Services.Configure(builder.Configuration.GetSection("AppConfiguration")); - var appConfig = builder.Configuration.GetSection("AppConfiguration").Get() ?? new AppConfiguration { JwtIssuer = "netcorepal", JwtAudience = "netcorepal" }; - - builder.Services.AddAuthentication().AddJwtBearer(options => - { - options.RequireHttpsMetadata = false; - options.TokenValidationParameters.ValidAudience = appConfig.JwtAudience; - options.TokenValidationParameters.ValidateAudience = true; - options.TokenValidationParameters.ValidIssuer = appConfig.JwtIssuer; - options.TokenValidationParameters.ValidateIssuer = true; - }); + // 配置JWT认证 + builder.Services.Configure(builder.Configuration.GetSection("AppConfiguration")); + var appConfig = builder.Configuration.GetSection("AppConfiguration").Get() ?? new AppConfiguration + { JwtIssuer = "netcorepal", JwtAudience = "netcorepal" }; + + builder.Services.AddAuthentication().AddJwtBearer(options => + { + options.RequireHttpsMetadata = false; + options.TokenValidationParameters.ValidAudience = appConfig.JwtAudience; + options.TokenValidationParameters.ValidateAudience = true; + options.TokenValidationParameters.ValidIssuer = appConfig.JwtIssuer; + options.TokenValidationParameters.ValidateIssuer = true; + }); builder.Services.AddNetCorePalJwt().AddRedisStore(); #endregion @@ -124,6 +124,7 @@ try { options.EnableSensitiveDataLogging(); } + options.EnableDetailedErrors(); }); builder.Services.AddUnitOfWork(); @@ -151,11 +152,11 @@ try builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies( - Assembly.GetExecutingAssembly(), - typeof(Fengling.Member.Application.Commands.Member.RegisterMemberCommand).Assembly, - typeof(Fengling.Member.Domain.Aggregates.Users.MemberEntity).Assembly, - typeof(Fengling.Member.Infrastructure.Repositories.MemberRepository).Assembly - ) + Assembly.GetExecutingAssembly(), + typeof(Fengling.Member.Application.Commands.Member.RegisterMemberCommand).Assembly, + typeof(Fengling.Member.Domain.Aggregates.Users.MemberEntity).Assembly, + typeof(Fengling.Member.Infrastructure.Repositories.MemberRepository).Assembly + ) .AddCommandLockBehavior() .AddKnownExceptionValidationBehavior() .AddUnitOfWorkBehaviors()); @@ -199,7 +200,7 @@ try builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - builder.Services.AddScoped(); + builder.Services.AddScoped(); #endregion @@ -246,7 +247,7 @@ try #endregion app.MapMetrics(); // 通过 /metrics 访问指标 - + // Code analysis endpoint app.MapGet("/code-analysis", () => { @@ -256,7 +257,7 @@ try ); return Results.Content(html, "text/html; charset=utf-8"); }); - + app.UseHangfireDashboard("/hangfire"); RecurringJob.AddOrUpdate( @@ -279,4 +280,4 @@ finally public partial class Program #pragma warning restore S1118 { -} +} \ No newline at end of file