Convert the OnBehalfOfUser header into a claim¶
Reads the OnBehalfOfUser request header and, if the caller is authenticated, adds it as a claim so later authorization steps can evaluate the delegated identity.
| Field | Value |
|---|---|
| Operation ID | OP-05 |
| Trigger | Every HTTP request |
| Inputs | HttpContext.User, request headers |
| Outputs | Claim added to the identity (side effect) |
| Primary components | OnBehalfOfUserClaimMiddleware.InvokeAsync, OnBehalfOfUserClaimService.SetOnBehalfOfUserClaim |
| Entry point | src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Middleware/OnBehalfOfUserClaimMiddleware.cs |
Steps¶
- Read
context.Userandcontext.Request.Headers(null-safe). - If headers contain
OnBehalfOfUser, read its value (multiple values are joined by theStringValues→stringconversion). (BR-NTLM-001) - If the value is null/whitespace, do nothing. (BR-NTLM-001)
- If the value is present: continue to step 4.
- If
User.Identityis aClaimsIdentityandIsAuthenticated, addClaim("OnBehalfOfUser", value); otherwise ignore the header. (BR-NTLM-002) - Always call
next(context)— the middleware never short-circuits. (BR-NTLM-003)
Process flow¶
flowchart TD
Start([HTTP request]) --> S1[Read User and headers]
S1 --> S2{OnBehalfOfUser header present and non-blank?}
S2 -->|No| S5[next context]
S2 -->|Yes| S3{Identity is authenticated ClaimsIdentity?}
S3 -->|No| S5
S3 -->|Yes| S4[Add OnBehalfOfUser claim]
S4 --> S5
S5 --> End([Pipeline continues])
Failure and edge-case behavior¶
- A null
context.Userwould throw on.Identitydereference; not expected under ASP.NET Core's own request pipeline.
Related documentation¶
Sources¶
src/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Middleware/OnBehalfOfUserClaimMiddleware.cssrc/SAIF.NetCore.NtlmApiAuth/src/SAIF.NetCore.NtlmApiAuth/Services/OnBehalfOfUserClaimService.cs