Table of Contents

Class ResolveUserFilter

Namespace
SEBT.Portal.Api.Filters
Assembly
SEBT.Portal.Api.dll

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
object
ResolveUserFilter

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

userRepository IUserRepository
logger ILogger<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

context ActionExecutingContext

The Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext.

next ActionExecutionDelegate

The 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.