Skip to content

fix: Add CancellationToken to Identity handlers#1169

Merged
iammukeshm merged 2 commits into
developfrom
fix/cancellation-token-identity-handlers-v2
Jan 25, 2026
Merged

fix: Add CancellationToken to Identity handlers#1169
iammukeshm merged 2 commits into
developfrom
fix/cancellation-token-identity-handlers-v2

Conversation

@iammukeshm
Copy link
Copy Markdown
Member

Summary

This PR adds proper CancellationToken handling to Identity authorization handlers.

Changes

PathAwareAuthorizationHandler.cs

  • Pass context.RequestAborted to WriteAsync call for proper cancellation support

RequiredPermissionAuthorizationHandler.cs

  • Extract CancellationToken from HttpContext.RequestAborted when available
  • Pass cancellation token to HasPermissionAsync call
  • Added .ConfigureAwait(false) for better async performance

Notes

The other handlers mentioned (UserRegisteredEmailHandler and TokenGeneratedLogHandler) were reviewed and already have proper CancellationToken handling:

  • UserRegisteredEmailHandler passes the ct parameter to _mailService.SendAsync
  • TokenGeneratedLogHandler only performs synchronous logging (no async calls)

Testing

These changes are backwards compatible and improve request cancellation handling without changing functionality.

jarvis added 2 commits January 25, 2026 15:03
- ChangePasswordEndpoint: Add RequireAuthorization() for logged-in users
- GetUserProfileEndpoint: Add RequireAuthorization() for logged-in users
- AssignUserRolesEndpoint: Add RequirePermission(Users.ManageRoles)
- GetUserPermissionsEndpoint: Add RequirePermission(Users.View)
- Add Users.ManageRoles permission constant

These endpoints were previously accessible without proper authorization checks.
- PathAwareAuthorizationHandler: Pass context.RequestAborted to WriteAsync
- RequiredPermissionAuthorizationHandler: Extract CancellationToken from HttpContext and pass to HasPermissionAsync

Note: UserRegisteredEmailHandler and TokenGeneratedLogHandler already have proper CancellationToken handling.
@iammukeshm iammukeshm merged commit 496350f into develop Jan 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant