Upload code
This commit is contained in:
39
src/Program.cs
Normal file
39
src/Program.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using ModeusSchedule.MSAuth.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(builder.Configuration["MODEUS_URL"]))
|
||||
{
|
||||
Console.Error.WriteLine("Ошибка: не задан URL для Modeus. Пожалуйста, укажите MODEUS_URL в файле конфигурации или переменных окружения.");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(builder.Configuration["MS_USERNAME"]) || string.IsNullOrWhiteSpace(builder.Configuration["MS_PASSWORD"]))
|
||||
{
|
||||
Console.Error.WriteLine("Ошибка: не заданы учетные данные для MicrosoftAuth. Пожалуйста, укажите MS_USERNAME и MS_PASSWORD в файле конфигурации или переменных окружения.");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
builder.Services.AddSingleton<MicrosoftAuthService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/auth/ms", async (MicrosoftAuthService mas, CancellationToken ct) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = await mas.GetJwtAsync(ct);
|
||||
return Results.Json(new { jwt = token });
|
||||
}
|
||||
catch (MicrosoftAuthInProgressException)
|
||||
{
|
||||
return Results.StatusCode(StatusCodes.Status429TooManyRequests);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.Problem(ex.Message, statusCode: 500);
|
||||
}
|
||||
})
|
||||
.WithName("GetMsJwt");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user