Add MedMind recovery and Steam authentication
This commit is contained in:
+28
@@ -9,6 +9,8 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading.RateLimiting;
|
||||
using System;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.WebHost.ConfigureKestrel(serverOptions => {});
|
||||
@@ -55,6 +57,22 @@ builder.Services.AddSingleton<BlacklistService>();
|
||||
builder.Services.AddSingleton<AuctionService>();
|
||||
builder.Services.AddSingleton<ChatService>();
|
||||
builder.Services.AddSingleton<AdminService>();
|
||||
builder.Services.AddSingleton<PasswordResetService>();
|
||||
builder.Services.AddSingleton<EmailService>();
|
||||
builder.Services.AddSingleton<SteamAuthService>();
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddRateLimiter(options =>
|
||||
{
|
||||
options.AddPolicy("password-reset", context => RateLimitPartition.GetFixedWindowLimiter(
|
||||
context.Connection.RemoteIpAddress?.ToString() ?? "unknown",
|
||||
_ => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
PermitLimit = 5,
|
||||
Window = TimeSpan.FromMinutes(15),
|
||||
QueueLimit = 0
|
||||
}));
|
||||
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
|
||||
});
|
||||
|
||||
var jwtKey = builder.Configuration["Jwt:Key"];
|
||||
var keyBytes = Encoding.UTF8.GetBytes(jwtKey);
|
||||
@@ -85,7 +103,9 @@ builder.Services.AddCors(options =>
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseRouting();
|
||||
app.UseCors("AllowAll");
|
||||
app.UseRateLimiter();
|
||||
|
||||
// Enable OPTIONS requests to reach controllers
|
||||
app.Use(async (context, next) =>
|
||||
@@ -109,4 +129,12 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var users = scope.ServiceProvider.GetRequiredService<UserService>();
|
||||
await users.BackfillNormalizedFieldsAsync();
|
||||
await users.EnsureIndexesAsync();
|
||||
await scope.ServiceProvider.GetRequiredService<PasswordResetService>().EnsureIndexesAsync();
|
||||
await scope.ServiceProvider.GetRequiredService<SteamAuthService>().EnsureIndexesAsync();
|
||||
}
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user