AppSurfaceAuthContext Context { get; }
Source
Gets the mapped AppSurface auth context.
Captures the result of mapping the current ASP.NET Core request principal into an AppSurface auth context.
Anonymous callers resolve successfully with AppSurfaceAuthContext.Anonymous. A non-null Failure means the adapter could not safely map the request, for example because there is no current HTTP request or an authenticated principal did not contain a configured subject claim.
AppSurfaceAuthContext Context { get; }
Source
Gets the mapped AppSurface auth context.
AppSurfaceAuthResult? Failure { get; }
Source
Gets the setup failure when the context could not be mapped safely.
bool Succeeded { get; }
Source
Gets a value indicating whether the current request principal mapped successfully.
Evaluates host-owned ASP.NET Core authorization policies and maps the outcome to AppSurface auth results.
This service does not create policies, register schemes, challenge responses, forbid responses, redirect callers, or mutate cookies. It evaluates policies registered by the host and returns a passive AppSurface result for downstream AppSurface surfaces.
Task<AppSurfaceAuthResult> AuthorizeAsync(string policyName, object? resource = null, CancellationToken cancellationToken = default)
Source
Evaluates a named ASP.NET Core authorization policy for the current HTTP request.
policyNameNon-empty host-owned policy name.resourceOptional authorization resource passed to ASP.NET Core policy evaluation. When null, the current HttpContext is used.cancellationTokenToken observed before and during policy lookup.A passive AppSurface auth result for the policy decision.
ArgumentExceptionpolicyName is null, empty, or whitespace.ASP.NET Core authorization execution itself does not expose a cancellation-token overload. Cancellation is observed before policy lookup, during asynchronous policy lookup, and immediately before policy evaluation. Exceptions from host policy providers or handlers are allowed to propagate so host bugs are not hidden as denials.
Provides the request-scoped AppSurface auth context mapped from the current ASP.NET Core HttpContext.
The accessor is intentionally passive: it reads the host-populated HttpContext.User and does not authenticate, challenge, forbid, redirect, or register host schemes. The mapped snapshot is memoized for the lifetime of the accessor scope so repeated module code sees a stable view of the request. Resolve it only from an ASP.NET Core request scope; outside a request it returns a missing-services snapshot instead of throwing.
AppSurfaceAspNetCoreAuthContextSnapshot GetCurrentContext()
Source
Gets the current request auth context snapshot, memoizing the result for the accessor scope.
A successful anonymous or authenticated snapshot when a request principal can be mapped; otherwise a snapshot carrying a safe missing-services or missing-subject setup failure.
A missing HttpContext is reported as AppSurfaceAuthReason.MissingServices so consumers can distinguish host setup/order issues from authorization denials.
Configures how ASP.NET Core request principals are mapped into AppSurface auth contracts.
These options do not configure authentication schemes, authorization policies, cookies, bearer tokens, identity providers, middleware, challenges, or forbids. ASP.NET Core remains the source of truth for those behaviors. The adapter only decides which already-authenticated claim represents the stable AppSurface subject identifier.
AppSurfaceAspNetCoreAuthOptions MapSubjectClaim(string claimType)
Source
Gives a claim type first priority when resolving the stable AppSurface subject identifier.
claimTypeClaim type that carries the host-owned stable subject id.The current options instance so calls can be chained from registration lambdas.
This method maps the subject identifier only. It does not map display names, emails, roles, permissions, scopes, or authorization truth. Host-owned ASP.NET Core policies remain responsible for permission decisions.
IReadOnlyList<string> SubjectClaimTypes { get; }
Source
Gets the ordered claim types used to resolve the stable AppSurface subject identifier.
Only authenticated ASP.NET Core identities are inspected. Claims on unauthenticated identities are ignored even when they use one of these claim types.
Registers the ASP.NET Core adapter for AppSurface auth contracts.
This module composes the neutral AppSurfaceAuthModule and registers adapter services only. It does not configure ASP.NET Core authentication schemes, authorization policies, middleware, challenges, forbids, redirects, cookies, identity providers, endpoint filters, RazorWire UI, or Minimal API helpers.
void ConfigureServices(StartupContext context, IServiceCollection services)
Source
Registers ASP.NET Core AppSurface auth adapter services.
contextStartup context for the current AppSurface composition pass.servicesService collection that receives adapter registrations.void RegisterDependentModules(ModuleDependencyBuilder builder)
Source
Registers the neutral AppSurface auth module dependency.
builderModule dependency builder for the current startup graph.Maps an ASP.NET Core ClaimsPrincipal into an AppSurface auth context snapshot.
Only authenticated identities are considered. Anonymous principals map to an anonymous success snapshot, while an authenticated principal without a configured stable subject claim maps to a missing-subject setup failure. This keeps AppSurface from silently treating a misconfigured authenticated request as either anonymous or allowed.
AppSurfaceAspNetCoreAuthContextSnapshot Map(ClaimsPrincipal? principal)
Source
Converts an ASP.NET Core principal into a neutral AppSurface auth-context snapshot.
principalThe principal populated by ASP.NET Core authentication middleware.An anonymous snapshot for null or unauthenticated principals, an authenticated snapshot when a configured subject claim is present, or a missing-subject failure snapshot for authenticated principals without a subject.
string? ResolveSubject(IReadOnlyList<ClaimsIdentity> identities)
Source
Resolves the first non-blank stable subject value using configured claim-type precedence.
identitiesAuthenticated identities whose claims are safe to inspect.The first matching subject value, or null when none is present.
Provides scoped access to the current ASP.NET Core request mapped into AppSurface auth contracts.
Resolve and use this service after ASP.NET Core authentication middleware has populated the current HttpContext.User. The mapping is lazy and memoized for the scoped service instance.
AppSurfaceAspNetCoreAuthContextSnapshot GetCurrentContext()
Source
Gets the current request's AppSurface auth context mapping snapshot.
A mapping snapshot. Anonymous callers resolve successfully; setup failures are exposed through AppSurfaceAspNetCoreAuthContextSnapshot.Failure.
Registers the ASP.NET Core AppSurface auth adapter.
IServiceCollection AddAppSurfaceAspNetCoreAuth(this IServiceCollection services, Action<AppSurfaceAspNetCoreAuthOptions>? configure = null)
Source
Adds AppSurface auth mapping services for an ASP.NET Core host.
servicesService collection that receives adapter registrations.configureOptional adapter options callback.The same service collection for chaining.
The adapter registers IHttpContextAccessor, AppSurface auth options, adapter options, and scoped adapter services. It intentionally does not call AddAuthentication, register authentication schemes, call AddAuthorization, create policies, add middleware, challenge, forbid, redirect, or mutate cookies. Host applications must keep those choices in their ASP.NET Core security setup.
Builds safe diagnostic metadata dictionaries for ASP.NET Core auth adapter setup failures.
Diagnostics identify missing services, policy names, and stable adapter diagnostic codes. They must not include raw claims, tokens, email addresses, display names, or other request-user secrets.
IReadOnlyDictionary<string, string> MissingService(Type serviceType, string diagnosticCode, string? policyName = null)
Source
Builds metadata for a missing ASP.NET Core service dependency.
serviceTypeThe service type that was required but unavailable.diagnosticCodeA stable adapter diagnostic code describing the missing dependency.policyNameOptional policy name associated with the setup failure.A safe metadata dictionary for an auth setup-failure result.
IReadOnlyDictionary<string, string> Policy(string diagnosticCode, string policyName)
Source
Builds metadata for a policy lookup or policy-related setup failure.
diagnosticCodeA stable adapter diagnostic code describing the policy failure.policyNameThe requested ASP.NET Core authorization policy name.A safe metadata dictionary for an auth setup-failure result.
Defines safe diagnostic metadata keys emitted by the ASP.NET Core auth adapter.
These keys are for setup diagnostics only. The adapter does not copy raw claims, tokens, emails, display names, or identity-provider payloads into result metadata.
Evaluates host-owned ASP.NET Core authorization policies and returns neutral AppSurface auth results.
This evaluator does not register or own schemes, policies, middleware, challenges, forbids, redirects, cookies, OIDC, or Identity. It resolves the host policy services from the current request, delegates authentication and authorization to ASP.NET Core, and maps the resulting principal through AppSurfaceAspNetCoreAuthContextMapper. Missing request services, missing policies, missing authentication setup, and authenticated principals without a subject are reported as setup failures with safe diagnostics; host handler exceptions still propagate.
Task<AppSurfaceAuthResult> AuthorizeAsync(string policyName, object? resource = null, CancellationToken cancellationToken = default)
Source
Evaluates a named ASP.NET Core authorization policy and maps the outcome to an AppSurface result.
policyNameThe non-blank host policy name to evaluate.resourceOptional resource passed to ASP.NET Core authorization handlers. When omitted, the current HttpContext is used, matching common ASP.NET Core request-policy behavior.cancellationTokenCancellation observed before and during policy lookup.AppSurfaceAuthOutcome.Allowed for successful authorization, AppSurfaceAuthOutcome.Challenge for unauthenticated policy outcomes, AppSurfaceAuthOutcome.Forbid for authenticated denials, or a setup-failure result for missing host services, missing policies, or missing stable subject claims.
Call this after the host has configured normal authentication and authorization services and middleware. ASP.NET Core policy evaluation does not accept a cancellation token, so handler execution is not cancellable through this adapter. Invalid operation exceptions that indicate missing framework authentication setup are converted to missing-services results; other host exceptions propagate.
AppSurfaceAuthResult MissingServices(Type missingService, string diagnosticCode, string policyName, string message)
Source
Creates a missing-services setup failure with safe ASP.NET Core auth adapter diagnostics.
missingServiceThe service type that was expected from host setup.diagnosticCodeStable diagnostic code for the missing setup condition.policyNamePolicy name being evaluated when the setup failure occurred.messageUser-facing failure message that avoids request secrets.A neutral setup-failure auth result.
ServiceResolution<TService> ResolveRequiredService<TService>(IServiceProvider requestServices, string diagnosticCode, string policyName, string message)
Source
Resolves a required request service and converts known missing-framework-service failures into setup failures.
TServiceThe request service contract required for policy evaluation.requestServicesCurrent request service provider.diagnosticCodeStable diagnostic code to use if the service cannot be resolved.policyNamePolicy name being evaluated.messageUser-facing failure message that avoids request secrets.A service resolution containing either the resolved service or a missing-services failure.
bool IsMissingServiceResolutionFailure(InvalidOperationException exception)
Source
Determines whether an InvalidOperationException represents missing DI setup.
exceptionThe exception thrown while resolving a request service.true when the exception is a known missing-service resolution failure.
bool IsMissingAuthenticationSetupFailure(InvalidOperationException exception)
Source
Determines whether an authentication exception represents missing host authentication setup.
exceptionThe exception thrown by ASP.NET Core policy authentication.true when the exception indicates missing authentication services or handlers.
Represents either a resolved request service or the setup failure produced when resolution failed.
TServiceThe request service contract being resolved.TService Service { get; }
Source
Gets the resolved service when resolution succeeded.
AppSurfaceAuthResult? Failure { get; }
Source
Gets the setup failure when resolution failed.