Class ResolveUserFilter
Action filter that resolves the authenticated user's numeric ID from their JWT sub claim and stashes it on HttpContext.Items. Controllers read the pre-resolved ID, keeping PII (email) out of controller code entirely. Also verifies the user still exists in the DB.
public class ResolveUserFilter
- Inheritance
-
objectResolveUserFilter
Constructors
ResolveUserFilter(IUserRepository, ILogger<ResolveUserFilter>)
Action filter that resolves the authenticated user's numeric ID from their JWT sub claim and stashes it on HttpContext.Items. Controllers read the pre-resolved ID, keeping PII (email) out of controller code entirely. Also verifies the user still exists in the DB.
public ResolveUserFilter(IUserRepository userRepository, ILogger<ResolveUserFilter> logger)
Parameters
userRepositoryIUserRepositoryloggerILogger<ResolveUserFilter>
Fields
UserIdKey
The HttpContext.Items key where the resolved user ID is stored.
public const string UserIdKey = "ResolvedUserId"
Field Value
- string
Methods
OnActionExecutionAsync(ActionExecutingContext, ActionExecutionDelegate)
Called asynchronously before the action, after model binding is complete.
public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
Parameters
contextActionExecutingContextThe Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext.
nextActionExecutionDelegateThe Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate. Invoked to execute the next action filter or the action itself.
Returns
- Task
A System.Threading.Tasks.Task that on completion indicates the filter has executed.