Skip to content

[Design]: Extensible Operation Pipeline & Transactional Lifecycle Hooks #157

Description

@mckaragoz

Summary

Introduce a centralized, extensible operation pipeline that allows applications to customize UltimateAuth operations through strongly typed lifecycle hooks without replacing existing endpoints or duplicating framework logic.

The pipeline should support application-specific validation, additional persistence operations, and transactional extensions while preserving UltimateAuth's unified authentication, authorization, and session model.

Target milestone: v0.4.0 — Infrastructure Expansion
Type: Enhancement
Priority: Design-first

Motivation

UltimateAuth provides ready-to-use endpoints and a Unified Client API for authentication, user management, credentials, authorization, and other operations.

However, real-world applications frequently need additional business behavior around these operations.

Examples include:

  • Creating an application profile when an UltimateAuth user is created.
  • Enforcing application-specific rules before deleting a user.
  • Creating tenant or organization memberships during provisioning.
  • Initializing application settings after registration.
  • Synchronizing application-owned records with user lifecycle operations.

Currently, these requirements may lead developers to implement custom endpoints, duplicate orchestration logic, or manually coordinate transactions and rollback behavior.

For co-hosted applications, these additional layers can introduce unnecessary complexity.

UltimateAuth should provide a simpler extension mechanism while retaining its existing endpoint and client experience.

Proposed Direction

Introduce a centralized Operation Pipeline that orchestrates supported UltimateAuth operations and allows developers to register application-specific lifecycle handlers.

Conceptually:

Unified Client / HTTP Endpoint / Direct Server Service
                         |
                         v
               UltimateAuth Operation
                         |
                         v
                Operation Pipeline
                         |
                 Authorization
                         |
                 BeforeExecute
                         |
                 Framework Execute
                         |
                  BeforeCommit
                         |
                Commit / Rollback
                         |
                  AfterCommit

The exact ordering of authorization, validation, transaction creation, and lifecycle hooks must be defined during the architecture review.

Hooks must never bypass or weaken mandatory framework security checks.

The pipeline should be integrated at the application service or operation execution layer, rather than exclusively at the HTTP endpoint layer.

This ensures consistent behavior regardless of whether an operation originates from the Unified Client API, an HTTP endpoint, or a future direct server-side execution API.

Developer Experience

Developers should register handlers centrally and only for the operations they want to extend.

Conceptual API (illustrative, not a proposed final contract):

builder.Services.AddUltimateAuthOperations(options =>
{
    options.For(UAuthOperations.Users.Create)
        .Before<ValidateUserCreation>()
        .BeforeCommit<CreateApplicationProfile>();

    options.For(UAuthOperations.Users.Delete)
        .Before<ValidateUserDeletion>();
});

A strongly typed handler contract could provide access to relevant operation context:

public interface IUAuthOperationHandler<TRequest, TResult>
{
    Task BeforeExecuteAsync(
        UAuthOperationContext<TRequest> context,
        CancellationToken ct);

    Task BeforeCommitAsync(
        UAuthOperationContext<TRequest, TResult> context,
        CancellationToken ct);
}

The final design may use separate phase-specific interfaces to avoid requiring handlers to implement unused methods.

Developers should not need to reimplement UltimateAuth's operation execution, authorization, transaction coordination, or rollback orchestration.

Operation Catalog

The architecture should introduce or identify a centralized operation catalog that defines supported extension points independently of individual HTTP routes.

Operation metadata may include:

  • Stable operation identifier
  • Operation category or domain
  • Request and result contracts
  • Supported lifecycle phases
  • Transaction capabilities
  • Security and authorization requirements
  • Sensitive data exposure restrictions

The catalog should distinguish between operations that support transactional extensions and operations where lifecycle hooks are inappropriate or require special treatment.

Examples:

Operation category Considerations
User creation and deletion Transactional application data extensions
Role and permission management Authorization and application-specific rules
Credential management Sensitive data and security invariants
Login and refresh Session security, token rotation, and response handling
Session validation Read-only behavior and performance-sensitive execution

The goal is a shared extensibility infrastructure, not necessarily identical hook behavior for every endpoint.

Lifecycle Semantics

The design should distinguish three execution phases.

BeforeExecute

Runs before the framework operation.

Potential uses:

  • Application-specific validation
  • Business rule enforcement
  • Preparation of operation-scoped data

Handlers may reject an operation but must not grant permissions that the framework would otherwise deny.

BeforeCommit

Runs after successful framework execution but before the participating transaction is committed.

Potential uses:

  • Creating application profiles
  • Adding related persistence records
  • Initializing application-owned entities
  • Updating related records within the same transaction

Failures should cause the participating transaction to roll back when atomic execution is supported.

AfterCommit

Runs only after the framework transaction has successfully committed.

Potential uses:

  • Notifications
  • Integration events
  • External system synchronization

AfterCommit failures cannot reverse an already committed transaction.

The design must explicitly define failure reporting, retries, and delivery guarantees. A transactional outbox may be considered for reliable external side effects.

Transaction Integration

The pipeline should investigate integration with the existing IUAuthAtomicExecutor infrastructure.

Where supported, UltimateAuth should coordinate transaction boundaries and rollback behavior.

Developers should be responsible for implementing application-specific persistence operations, not general transaction orchestration.

Important requirements:

  • Transactional guarantees must be explicit.
  • Application persistence must participate in the same transaction to receive atomic rollback guarantees.
  • Separate databases or external services must not be represented as automatically atomic.
  • Unsupported transaction configurations must not silently degrade promised guarantees.
  • Nested operations and transaction participation must be defined.
  • Handler ordering, failure propagation, cancellation, and execution retries must be deterministic.
  • Compensation mechanisms, if introduced, must be distinguished from database rollback.

The initial design should determine whether existing EF Core transaction integration can safely support application-owned DbContexts and stores.

Security Requirements

Lifecycle extensibility must preserve UltimateAuth's security invariants.

Handlers must not be able to:

  • Bypass authentication or authorization policies.
  • Impersonate another actor or tenant.
  • Override mandatory session or device validation.
  • Circumvent credential or token security requirements.
  • Access sensitive authentication material without an explicitly justified contract.
  • Mutate trusted operation context in ways that invalidate security decisions.

Operation contexts should expose only the information required for the selected extension point.

Security-critical operations may require restricted or unavailable lifecycle phases.

Scope

In scope

  • Audit existing operation execution boundaries and IUAuthAtomicExecutor.
  • Design a centralized operation catalog and pipeline.
  • Define strongly typed lifecycle handler contracts.
  • Support centralized DI registration and operation-specific configuration.
  • Establish deterministic handler ordering and failure behavior.
  • Define transactional and non-transactional lifecycle semantics.
  • Implement a limited proof of concept using user creation.
  • Validate compatibility with existing HTTP and direct-service execution paths.
  • Add focused security, transaction, and regression tests.
  • Document supported operations and extension capabilities.

Out of scope

  • Replacing existing UltimateAuth endpoints or the Unified Client API.
  • Introducing custom endpoint requirements for standard operations.
  • Allowing lifecycle hooks to bypass security policies.
  • Automatically providing distributed transactions.
  • Requiring developers to implement framework execution or rollback logic.
  • Exposing internal credential or token data through generic hooks.
  • Enabling every endpoint without reviewing its operation semantics.
  • Large-scale refactoring unrelated to operation extensibility.

Acceptance Criteria

  • A documented architecture identifies the appropriate shared operation execution boundary.
  • A centralized operation catalog or equivalent mechanism identifies supported extension points.
  • Developers can register strongly typed handlers for specific operations through DI.
  • Existing framework execution and authorization remain under UltimateAuth control.
  • Supported operations invoke lifecycle handlers consistently across HTTP and direct-service execution paths.
  • Transactional handlers participate in the same transaction where explicitly supported.
  • Failures before commit correctly roll back all participating changes.
  • AfterCommit behavior and failure guarantees are explicitly documented.
  • Handler ordering, cancellation, retries, and nested execution behavior are defined and tested.
  • Security-sensitive contexts do not expose unnecessary credentials or tokens.
  • Existing Unified Client APIs and endpoints remain backward compatible.
  • A user-creation proof of concept demonstrates application profile creation without a custom endpoint.
  • Documentation explains supported phases, transaction limitations, and recommended usage patterns.

Implementation Strategy

Start with an architecture review and a narrow user-creation proof of concept.

Do not immediately integrate the pipeline into every existing endpoint.

Once transaction behavior, security boundaries, and public contracts are validated, expand support incrementally across operation families.

Prefer reuse of existing authorization, atomic execution, and application service infrastructure over introducing a parallel orchestration system.

Design Principle

Extend operations without replacing them.

UltimateAuth should own the execution pipeline, security enforcement, and supported transaction boundaries, while application developers provide only the business behavior specific to their applications.

The Unified Client API remains the default integration experience; lifecycle extensions provide a controlled way to customize the underlying operations without duplicating endpoints or framework logic.

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