Login route, database compose file
Some checks failed
Build Backend and Frontend / Build & Test .NET Backend (push) Has been cancelled
Build Backend and Frontend / Build Frontend (push) Has been cancelled

This commit is contained in:
Simon Lübeß
2025-06-04 16:42:13 +02:00
parent efd69f63b0
commit a5727f0f51
5 changed files with 104 additions and 21 deletions

View File

@ -45,16 +45,16 @@ AuthenticationSettings? authSettings = authSettingsSection.Get<AuthenticationSet
// ValidateAudience = false
// };
// });
builder.Services.AddAuthorization(options =>
{
options.AddPolicy(nameof(UserRole.Developer), policy => policy.RequireRole(nameof(UserRole.Developer)));
options.AddPolicy(nameof(UserRole.User), policy =>
{
// Also allow Developers to do anything a user can do.
policy.RequireRole(nameof(UserRole.User), nameof(UserRole.Developer));
});
});
//
// builder.Services.AddAuthorization(options =>
// {
// options.AddPolicy(nameof(UserRole.Developer), policy => policy.RequireRole(nameof(UserRole.Developer)));
// options.AddPolicy(nameof(UserRole.User), policy =>
// {
// // Also allow Developers to do anything a user can do.
// policy.RequireRole(nameof(UserRole.User), nameof(UserRole.Developer));
// });
// });
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
@ -145,6 +145,27 @@ app.MapGet("/user", (ClaimsPrincipal user) =>
Results.Ok(new { message = $"Authenticated as { user?.Identity?.Name }" });
}).RequireAuthorization(nameof(UserRole.User));
app.MapGet("/auth/validate", async (HttpContext context, UserManager<IdentityUser> userManager) =>
{
if (!context.User.Identity?.IsAuthenticated ?? true)
{
return Results.Unauthorized();
}
IdentityUser? user = await userManager.GetUserAsync(context.User);
if (user is null)
{
return Results.InternalServerError("User not found?!");
}
return Results.Ok(new
{
user.Id,
user.Email
});
}).RequireAuthorization();
app.MapGet("/ephemeral_token", async () =>
{
//if (apiKey == null)