Login route, database compose file
This commit is contained in:
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user