Skip to main content

InMemoryLongPollingService Class

Abblix.Oidc.Server

Abblix.Oidc.Server.Features.BackChannelAuthentication

InMemoryLongPollingService Class

In-memory implementation of backchannel authentication status notifier using TaskCompletionSource. Suitable for single-server deployments or development environments.

public class InMemoryLongPollingService : Abblix.Oidc.Server.Features.BackChannelAuthentication.Interfaces.IBackChannelLongPollingService

Inheritance System.Object → InMemoryLongPollingService

Implements IBackChannelLongPollingService

Remarks

This implementation uses an in-memory dictionary of TaskCompletionSource objects to coordinate between authentication completion and waiting token requests. When authentication status changes, all waiting tasks are signaled via TaskCompletionSource.SetResult().

Characteristics:
  • Thread-safe using ConcurrentDictionary
  • Automatic cleanup of completed waiters
  • Supports multiple simultaneous waiters per auth_req_id
  • Memory efficient (only stores active waiters)
  • NOT suitable for multi-server deployments (notifications are local only)
For Multi-Server Deployments:

Use a distributed implementation based on Redis Pub/Sub, SignalR backplane, or message queue.

Constructors

InMemoryLongPollingService(ILogger<InMemoryLongPollingService>) Constructor

In-memory implementation of backchannel authentication status notifier using TaskCompletionSource. Suitable for single-server deployments or development environments.

public InMemoryLongPollingService(Microsoft.Extensions.Logging.ILogger<Abblix.Oidc.Server.Features.BackChannelAuthentication.InMemoryLongPollingService> logger);

Parameters

logger Microsoft.Extensions.Logging.ILogger<InMemoryLongPollingService>

Remarks

This implementation uses an in-memory dictionary of TaskCompletionSource objects to coordinate between authentication completion and waiting token requests. When authentication status changes, all waiting tasks are signaled via TaskCompletionSource.SetResult().

Characteristics:
  • Thread-safe using ConcurrentDictionary
  • Automatic cleanup of completed waiters
  • Supports multiple simultaneous waiters per auth_req_id
  • Memory efficient (only stores active waiters)
  • NOT suitable for multi-server deployments (notifications are local only)
For Multi-Server Deployments:

Use a distributed implementation based on Redis Pub/Sub, SignalR backplane, or message queue.

Methods

InMemoryLongPollingService.NotifyStatusChangeAsync(string, BackChannelAuthenticationStatus) Method

Notifies all waiting requests that the authentication status has changed. Signals all TaskCompletionSource objects waiting for this auth_req_id.

public System.Threading.Tasks.Task NotifyStatusChangeAsync(string authenticationRequestId, Abblix.Oidc.Server.Features.BackChannelAuthentication.BackChannelAuthenticationStatus newStatus);

Parameters

authenticationRequestId System.String
newStatus BackChannelAuthenticationStatus

Implements NotifyStatusChangeAsync(string, BackChannelAuthenticationStatus)

Returns

System.Threading.Tasks.Task

InMemoryLongPollingService.WaitForStatusChangeAsync(string, TimeSpan, CancellationToken) Method

Waits for a status change notification for the specified authentication request. Uses TaskCompletionSource to efficiently wait without blocking threads.

public System.Threading.Tasks.Task<bool> WaitForStatusChangeAsync(string authenticationRequestId, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

authenticationRequestId System.String
timeout System.TimeSpan
cancellationToken System.Threading.CancellationToken

Implements WaitForStatusChangeAsync(string, TimeSpan, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Boolean>