add lodestone auth, add rate limiting middleware

This commit is contained in:
Stanley Dimant
2022-08-01 17:41:46 +02:00
parent 4d3226aa8b
commit e0f273a020
14 changed files with 1102 additions and 43 deletions

View File

@@ -16,6 +16,8 @@ using Prometheus;
using WebSocketOptions = Microsoft.AspNetCore.Builder.WebSocketOptions;
using Microsoft.Extensions.FileProviders;
using Microsoft.AspNetCore.Authorization;
using MareSynchronosServer.Discord;
using AspNetCoreRateLimit;
namespace MareSynchronosServer
{
@@ -41,6 +43,13 @@ namespace MareSynchronosServer
hubOptions.StreamBufferCapacity = 200;
});
services.AddMemoryCache();
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting"));
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
services.AddInMemoryRateLimiting();
services.AddSingleton<SystemInfoService, SystemInfoService>();
services.AddSingleton<IUserIdProvider, IdBasedUserIdProvider>();
services.AddTransient(_ => Configuration);
@@ -55,6 +64,7 @@ namespace MareSynchronosServer
services.AddHostedService<FileCleanupService>();
services.AddHostedService(provider => provider.GetService<SystemInfoService>());
services.AddHostedService<DiscordBot>();
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddAuthentication(options =>
@@ -63,6 +73,8 @@ namespace MareSynchronosServer
})
.AddScheme<AuthenticationSchemeOptions, SecretKeyAuthenticationHandler>(SecretKeyAuthenticationHandler.AuthScheme, options => { });
services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -81,6 +93,8 @@ namespace MareSynchronosServer
app.UseHsts();
}
app.UseIpRateLimiting();
app.UseStaticFiles();
app.UseHttpLogging();