Resolve the current identity service¶
Resolves which concrete IIdentityService implementation represents the current user, switching on the authentication scheme when multiple identity services are registered.
Security enforcement points: EP-09 (identity selection).
| Field | Value |
|---|---|
| Operation ID | OP-12 |
| Trigger | Consumer code resolves IIdentityServiceAccessor.IdentityService from DI. |
| Inputs | The current HttpContext (may be null), the registered identity services. |
| Outputs | An IIdentityService instance (TokenIdentityService or WinIdentityService, or whatever is registered for the single-accessor case). |
| Primary components | MultiIdentityServiceAccessor.IdentityService / IdentityServiceAccessor.IdentityService |
| Entry point | src/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/Identity/MultiIdentityServiceAccessor.cs |
Steps¶
- Multi: the scheme is
AuthenticationSchemeSelector(HttpContext)— or the IIS scheme ifHttpContextis null (BR-AUTH-016) AuthenticationSchemeSelectoris a mutable staticFunc<HttpContext, string>field onAuthenticationServiceExtensions; its default implementation returns the JwtBearer scheme when theAuthorizationrequest header starts with"Bearer ", and the IIS/Windows scheme otherwise.
Origin: Step 1's scheme-selection logic is implemented in Select the dual authentication scheme (
SAIF.NetCore.AuthService) and executed on behalf of this operation. 2. For the JwtBearer scheme, resolveTokenIdentityService; for any other scheme, resolveWinIdentityService. 3. Single:IdentityServiceAccessoris constructed with anIServiceProviderand anIHttpContextAccessor, which it stores; it does not resolve or cacheIIdentityServicein its constructor. Each access of itsIdentityServicegetter callsServiceProvider.GetService(typeof(IIdentityService))fresh — a service-location call, not a captured/injected instance — so the returned implementation depends on whicheverIIdentityServiceregistration (AddTokenIdentityServiceorAddWinIdentityService) and DI lifetime the consumer configured; there is no scheme switching on this path.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([IdentityService resolved]) --> HasCtx{HttpContext present?}
HasCtx -->|No| Win([Resolve WinIdentityService])
HasCtx -->|Yes| Scheme[AuthenticationSchemeSelector HttpContext]
Scheme --> IsJwt{JwtBearer scheme?}
IsJwt -->|Yes| Token([Resolve TokenIdentityService])
IsJwt -->|No| Win2([Resolve WinIdentityService])
Failure and edge-case behavior¶
- With no
HttpContext, the multi accessor defaults toWinIdentityService, whoseUserIdis then null and throwsNullReferenceExceptionon the next authorization call*.
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. Statements marked with**could not be confirmed; treat as unknown until verified.
Sources¶
src/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/Identity/MultiIdentityServiceAccessor.cssrc/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/SAIF.NetCore.AuthService/Identity/IdentityServiceAccessor.cs