Compare commits

..

2 Commits

Author SHA1 Message Date
0ed62ad8ed feat: Добавил авторизацию по api ключу 2025-11-14 00:23:37 +03:00
71bebfdf84 Upload code 2025-11-14 00:23:05 +03:00
2 changed files with 31 additions and 0 deletions

View File

@@ -14,10 +14,27 @@ if (string.IsNullOrWhiteSpace(builder.Configuration["MS_USERNAME"]) || string.Is
Environment.Exit(1);
}
var configuredApiKey = builder.Configuration["API_KEY"];
builder.Services.AddSingleton<MicrosoftAuthService>();
var app = builder.Build();
if (!string.IsNullOrWhiteSpace(configuredApiKey))
{
app.Use(async (context, next) =>
{
if (!context.Request.Headers.TryGetValue("X-API-Key", out var providedKey) || !string.Equals(providedKey, configuredApiKey, StringComparison.Ordinal))
{
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
await context.Response.WriteAsync("Unauthorized");
return;
}
await next();
});
}
app.MapGet("/auth/ms", async (MicrosoftAuthService mas, CancellationToken ct) =>
{
try

View File

@@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5258",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}