Skip to content

[Design]: Server-Side Execution Context for Direct Service Integration #156

Description

@mckaragoz

Summary

Introduce an optional, secure server-side execution context API that allows applications to invoke UltimateAuth application services directly without requiring an HTTP endpoint for every operation.

This capability should support Blazor Server, UAuthHub, and other co-hosted application architectures where UltimateAuth and application business logic run within the same server process.

The existing Unified Client API and HTTP endpoints remain the default integration path. Server-side execution is an additional option, not a replacement or a separate authentication model.

Target milestone: v0.4.0 (Infrastructure Expansion), or earlier if the design and security requirements can be satisfied.

Motivation

UltimateAuth provides a unified client experience across different application models.

However, applications that host their business logic and authentication services together can benefit from direct dependency injection and application service calls.

For example, Blazor Server components can access server-side services without creating additional application HTTP endpoints.

Currently, authenticated UltimateAuth operations may depend on HTTP-derived authentication contexts, including cookies, device identifiers, and client profile information.

Interactive Blazor Server events do not necessarily have a current HTTP request, making direct authentication context creation unreliable.

Applications can solve this by routing operations through authenticated browser HTTP requests, but this introduces additional endpoints, DTOs, transport handling, and serialization for operations that could otherwise execute directly.

This is especially relevant for small and medium-sized applications using Blazor Server or UAuthHub with co-hosted business services.

Proposed Direction

Provide an optional server-side API for obtaining a validated UltimateAuth execution context and using it with existing application services.

Conceptual example (API names are illustrative):

@inject IUAuthExecutionContext UAuthContext
@inject IUserApplicationService Users

private async Task CreateUserAsync()
{
    var context = await UAuthContext.GetValidatedAsync(
        UAuthActions.Users.CreateAdmin,
        "users");

    await Users.CreateUserAsync(context, request);
}

The API should:

  • Allow direct invocation of existing UltimateAuth application services.
  • Avoid requiring application-specific HTTP endpoints solely to obtain an authenticated context.
  • Integrate naturally with dependency injection.
  • Preserve existing AuthFlowContext, AccessContext, policy, and authorization semantics.
  • Support Blazor Server and UAuthHub, without hard-coding the abstraction to a single UI framework.
  • Remain optional and compatible with the existing Unified Client API.

The precise public API, naming, and implementation should be determined during design.

Architecture

The goal is to separate authentication context acquisition from the transport used to acquire it.

UltimateAuth should retain a single security and authorization model while supporting different execution environments.

Conceptually:

                  UltimateAuth Core
             Session / Device / Policies
                        |
             Shared Validation Model
                        |
             +----------+----------+
             |                     |
       HTTP Execution       Server Execution
             |                     |
       Unified Client       Direct DI Services
             |                     |
       Browser / WASM       Blazor Server / UAuthHub
             |                     |
             +----------+----------+
                        |
             UltimateAuth Services

Both paths must enforce equivalent security guarantees appropriate to their execution environments.

The server-side path must not bypass authentication, session validation, device binding, authorization policies, tenant isolation, or revocation semantics.

Security Requirements

A server-side execution context must be derived from a trusted, authenticated session.

A Blazor circuit, cached ClaimsPrincipal, or component-scoped authentication state must not automatically be treated as proof of a currently valid UltimateAuth session.

The design must address:

  • Secure session and actor binding
  • Device identity and binding validation
  • Current session validity and revocation
  • Logout and session expiration
  • Circuit reconnects and identity changes
  • Concurrent operations and context isolation
  • Tenant and resource authorization
  • Prevention of actor or context impersonation
  • Fail-closed behavior when validation cannot be completed

Sensitive operations must not rely solely on authentication state captured when a circuit was initially established.

The design should determine whether session validation can be performed directly through existing server-side validation services using a securely bound session reference.

Avoid introducing mutable shared authentication state, bypass flags, or synthetic HTTP contexts.

Unified Compatibility

This feature must preserve UltimateAuth's unified architecture.

The following should remain consistent across HTTP and server-side execution:

  • Authentication and session semantics
  • Root / Chain / Session lifecycle
  • Authorization and policy evaluation
  • Device security guarantees
  • Tenant isolation
  • Revocation behavior
  • Application service contracts

Transport-specific implementation details may differ, but the underlying security model must remain unified.

Existing Unified Client APIs and HTTP endpoints must continue to work without behavioral changes.

Login, logout, and other operations requiring HTTP response cookie handling may continue using the existing browser transport.

Scope

In scope

  • Evaluate existing authentication flow and context factory abstractions.
  • Identify HTTP-specific dependencies that prevent safe direct service execution.
  • Design a reusable server-side execution context abstraction.
  • Investigate integration with Blazor Server and UAuthHub.
  • Reuse existing session validation, policy, and authorization infrastructure.
  • Define lifecycle, revocation, device-binding, and concurrency guarantees.
  • Add focused security and integration tests.
  • Provide a minimal DI integration and usage example if the design is validated.

Out of scope

  • Replacing the Unified Client API.
  • Removing or duplicating existing UltimateAuth endpoints.
  • Introducing a separate Blazor authentication system.
  • Weakening Device ID or session validation.
  • Automatically trusting circuit authentication state.
  • Redesigning the Root / Chain / Session model.
  • Adding application-specific business workflows to UltimateAuth.
  • Rewriting login/logout cookie handling around circuit events.

Acceptance Criteria

  • A documented architecture defines how server-side contexts are securely acquired and validated.
  • Blazor Server can invoke protected UltimateAuth application services directly without an additional application HTTP endpoint for the operation.
  • UAuthHub co-hosted application scenarios are evaluated and supported where technically appropriate.
  • Session revocation, expiration, device mismatch, reconnect, and actor isolation are covered by regression tests.
  • Existing authorization policies and tenant boundaries are enforced without bypasses.
  • The integration does not rely on a stale HttpContext or cached circuit identity as sufficient authorization.
  • The Unified Client API and existing HTTP behavior remain backward compatible.
  • A concise example demonstrates direct service integration and explains when to prefer it over the Unified Client API.

Design Principle

One authentication model, multiple execution paths.

UltimateAuth should allow developers to choose the simplest secure integration for their application architecture without requiring duplicate endpoints or sacrificing unified authentication guarantees.

Activity

  1. added this to the v0.4.0 milestone on Nov 9, 2026
  2. added theissue type on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions