0052725b88
- Created UserViewSheet component to display user details including username, full name, role, status, and timestamps. - Created RoleViewSheet component to display role details including name, level, status, creation date, and associated permissions. - Introduced permissions configuration in a new permissions.ts file, defining categories and permission codes for better management. - Implemented middleware for authentication, ensuring access control for protected routes.
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Text.Encodings.Web;
|
|
|
|
namespace Distribution.Middleware;
|
|
|
|
/// <summary>
|
|
/// Authentication handler that exists solely to provide Challenge (401) and Forbid (403)
|
|
/// responses for UseAuthorization(). Token validation is handled upstream by AuthMiddleware,
|
|
/// so HandleAuthenticateAsync returns NoResult to leave HttpContext.User untouched.
|
|
/// </summary>
|
|
public class BearerResponseHandler(
|
|
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
|
ILoggerFactory logger,
|
|
UrlEncoder encoder) : AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
|
|
{
|
|
protected override Task<AuthenticateResult> HandleAuthenticateAsync() =>
|
|
Task.FromResult(AuthenticateResult.NoResult());
|
|
|
|
protected override Task HandleChallengeAsync(AuthenticationProperties properties)
|
|
{
|
|
Response.StatusCode = StatusCodes.Status401Unauthorized;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
protected override Task HandleForbiddenAsync(AuthenticationProperties properties)
|
|
{
|
|
Response.StatusCode = StatusCodes.Status403Forbidden;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|