Skip to content

Commit d65c8e7

Browse files
author
jarvis
committed
fix: Add CancellationToken to Identity handlers
- PathAwareAuthorizationHandler: Pass context.RequestAborted to WriteAsync - RequiredPermissionAuthorizationHandler: Extract CancellationToken from HttpContext and pass to HasPermissionAsync Note: UserRegisteredEmailHandler and TokenGeneratedLogHandler already have proper CancellationToken handling.
1 parent d3a5a5e commit d65c8e7

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/Modules/Identity/Modules.Identity/Authorization/PathAwareAuthorizationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Authorization.Policy;
33
using Microsoft.AspNetCore.Http;
44

@@ -38,7 +38,7 @@ public async Task HandleAsync(
3838

3939
// If no endpoint is found, return 404 explicitly
4040
context.Response.StatusCode = StatusCodes.Status404NotFound;
41-
await context.Response.WriteAsync("Endpoint not found.");
41+
await context.Response.WriteAsync("Endpoint not found.", context.RequestAborted).ConfigureAwait(false);
4242
return;
4343
}
4444

src/Modules/Identity/Modules.Identity/Authorization/RequiredPermissionAuthorizationHandler.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FSH.Framework.Shared.Identity.Claims;
1+
using FSH.Framework.Shared.Identity.Claims;
22
using FSH.Modules.Identity.Contracts.Services;
33
using Microsoft.AspNetCore.Authorization;
44
using Microsoft.AspNetCore.Http;
@@ -12,9 +12,10 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext
1212
ArgumentNullException.ThrowIfNull(context);
1313
ArgumentNullException.ThrowIfNull(requirement);
1414

15+
var httpContext = context.Resource as HttpContext;
1516
var endpoint = context.Resource switch
1617
{
17-
HttpContext httpContext => httpContext.GetEndpoint(),
18+
HttpContext ctx => ctx.GetEndpoint(),
1819
Endpoint ep => ep,
1920
_ => null,
2021
};
@@ -27,7 +28,9 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext
2728
context.Succeed(requirement);
2829
return;
2930
}
30-
if (context.User?.GetUserId() is { } userId && await userService.HasPermissionAsync(userId, requiredPermissions.First()))
31+
32+
var cancellationToken = httpContext?.RequestAborted ?? CancellationToken.None;
33+
if (context.User?.GetUserId() is { } userId && await userService.HasPermissionAsync(userId, requiredPermissions.First(), cancellationToken).ConfigureAwait(false))
3134
{
3235
context.Succeed(requirement);
3336
}

0 commit comments

Comments
 (0)