---
title: Get the current user name
summary: Resolves the current user's name for client-side header configuration.
status: draft
owner: SAIF Platform Team
last_reviewed: 2026-10-02
library: SAIF.NetCore.NtlmApiAuth
reference_type: package
operation_id: OP-08
trigger: Called by Configure an outbound client to send OnBehalfOfUser, or directly by consumer code
---

# 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](configure-outbound-client-header.md), 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

1. MVC: read `IHttpContextAccessor.HttpContext.User.Identity.Name` (null-safe). Blazor: synchronously block on `AuthenticationStateProvider.GetAuthenticationStateAsync()` and read `User.Identity.Name`. ([BR-NTLM-013](../business-rules.md#br-ntlm-013-current-user-source-depends-on-client-type))
2. If `friendlyName` (the default), return the `DomainlessUser()` form of the name; otherwise return the raw name. Return `null` if there is no identity. ([BR-NTLM-011](../business-rules.md#br-ntlm-011-user-name-normalization))

## Process flow

```mermaid
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.GetCurrentUser` blocks 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 `null` when there is no `HttpContext` (MVC) or no authentication state (Blazor), e.g. in background work or Blazor prerendering.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

> **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.cs`
- `src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Services/BlazorCurrentUserService.cs`
