Get the current user name¶
Resolves the current user's name from the client app's identity source (HttpContext.User for MVC, AuthenticationStateProvider for Blazor), optionally stripping the domain.
| Field | Value |
|---|---|
| Operation ID | OP-08 |
| Trigger | Called by Configure an outbound client to send OnBehalfOfUser, or directly by consumer code |
| Inputs | friendlyName (default true) |
| Outputs | User name string, or null |
| Primary components | ICurrentUserService.GetCurrentUser(friendlyName) — MvcCurrentUserService, BlazorCurrentUserService |
| Entry point | src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Services/MvcCurrentUserService.cs, Services/BlazorCurrentUserService.cs |
Steps¶
- MVC: read
IHttpContextAccessor.HttpContext.User.Identity.Name(null-safe). Blazor: synchronously block onAuthenticationStateProvider.GetAuthenticationStateAsync()and readUser.Identity.Name. (BR-NTLM-013) - If
friendlyName(the default), return theDomainlessUser()form of the name; otherwise return the raw name. Returnnullif there is no identity. (BR-NTLM-011)
Process flow¶
flowchart TD
Start([GetCurrentUser friendlyName]) --> D{Client type}
D -->|MVC| S1[Read HttpContext.User.Identity.Name]
D -->|Blazor| S2["Block on GetAuthenticationStateAsync,<br>read User.Identity.Name"]
S1 --> S3{friendlyName?}
S2 --> S3
S3 -->|Yes| S4[Return DomainlessUser name]
S3 -->|No| S5[Return raw name]
S4 --> End([Name or null])
S5 --> End
Failure and edge-case behavior¶
BlazorCurrentUserService.GetCurrentUserblocks synchronously on an async call (GetAwaiter().GetResult()); this pattern can deadlock in some synchronization contexts, though no deadlock has been observed or tested in this run.*- Returns
nullwhen there is noHttpContext(MVC) or no authentication state (Blazor), e.g. in background work or Blazor prerendering.
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Services/MvcCurrentUserService.cssrc/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Services/BlazorCurrentUserService.cs