Skip to content

SessionClientRegistry Class

Keeps the clients of a session as a numbered list in entity storage, one key per client, under a generation that bounds how long the list lives: at least a retention after the session's last authorization, and at most two.

C#
public class SessionClientRegistry : Abblix.Oidc.Server.Features.Storages.ISessionClientRegistry

Inheritance System.Object → SessionClientRegistry

Implements ISessionClientRegistry

Remarks

A client is added by claiming the first free position of the current generation, so two authorizations arriving together claim two positions instead of writing one list twice. The list is read from the first position up to the first free one, so no record of a generation is written to expire before the generation itself, and a session whose generation is gone starts a new one instead of writing into positions of the old one that may already have emptied. That holds while the clocks of the server's instances agree: a record written by an instance whose clock is behind the one that last renewed the generation ends earlier by the difference, and a logout in that moment does not reach the clients listed after it.

A session goes on under its id when its end user signs in again, so the list is renewed rather than left to expire on the schedule of the first client: the generation and its records are written to last two retentions, and once a retention has passed since the last renewal, the next authorization keeps every one of them two retentions from then. A renewal moves only the expiry of what is still stored, so it never brings back a generation that has ended or writes an old one over the one that replaced it. A renewal of a generation that is replaced while the renewal runs gives the replacement the end it computed, which is earlier than the replacement's own by the time between the two, so the replacement may end that much less than a retention after an authorization.

A second key per client says the client is already recorded, so recording a client the session already knows costs four reads, the generation, the marker, the generation again and the note of the last renewal, rather than a search of the list. A renewal costs a read and two extensions per client on top, once a retention.

Constructors

SessionClientRegistry(IEntityStorage, IEntityStorageKeyFactory, IOptions<OidcOptions>, TimeProvider, ILogger<SessionClientRegistry>) Constructor

Keeps the clients of a session as a numbered list in entity storage, one key per client, under a generation that bounds how long the list lives: at least a retention after the session's last authorization, and at most two.

C#
public SessionClientRegistry(Abblix.Oidc.Server.Features.Storages.IEntityStorage storage, Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory keyFactory, Microsoft.Extensions.Options.IOptions<Abblix.Oidc.Server.Common.Configuration.OidcOptions> options, System.TimeProvider clock, Microsoft.Extensions.Logging.ILogger<Abblix.Oidc.Server.Features.Storages.SessionClientRegistry> logger);

Parameters

storage IEntityStorage

Where the records are claimed and read.

keyFactory IEntityStorageKeyFactory

Names the generation, each position, each client and the last renewal.

options Microsoft.Extensions.Options.IOptions<OidcOptions>

Supplies how long a generation lasts after the session's last authorization.

clock System.TimeProvider

Supplies the moment a generation's end is measured from.

logger Microsoft.Extensions.Logging.ILogger<SessionClientRegistry>

Reports a session whose list is full.

Remarks

A client is added by claiming the first free position of the current generation, so two authorizations arriving together claim two positions instead of writing one list twice. The list is read from the first position up to the first free one, so no record of a generation is written to expire before the generation itself, and a session whose generation is gone starts a new one instead of writing into positions of the old one that may already have emptied. That holds while the clocks of the server's instances agree: a record written by an instance whose clock is behind the one that last renewed the generation ends earlier by the difference, and a logout in that moment does not reach the clients listed after it.

A session goes on under its id when its end user signs in again, so the list is renewed rather than left to expire on the schedule of the first client: the generation and its records are written to last two retentions, and once a retention has passed since the last renewal, the next authorization keeps every one of them two retentions from then. A renewal moves only the expiry of what is still stored, so it never brings back a generation that has ended or writes an old one over the one that replaced it. A renewal of a generation that is replaced while the renewal runs gives the replacement the end it computed, which is earlier than the replacement's own by the time between the two, so the replacement may end that much less than a retention after an authorization.

A second key per client says the client is already recorded, so recording a client the session already knows costs four reads, the generation, the marker, the generation again and the note of the last renewal, rather than a search of the list. A renewal costs a read and two extensions per client on top, once a retention.

Methods

SessionClientRegistry.AddClientAsync(TenantDefinition, string, string, CancellationToken) Method

Records that a client signed in to a session, and keeps the clients recorded for the session readable for at least SessionClientsRetention from now. Recording a client already recorded lists it no second time.

C#
public System.Threading.Tasks.Task AddClientAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition tenant, string sessionId, string clientId, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

tenant TenantDefinition

The tenant the session belongs to.

sessionId System.String

The session the client signed in to.

clientId System.String

The client.

cancellationToken System.Threading.CancellationToken

Cancels the operation.

Implements AddClientAsync(TenantDefinition, string, string, CancellationToken)

Returns

System.Threading.Tasks.Task

Remarks

A session goes on under its id when its end user signs in again, so an implementation that let the list expire a fixed time after its first client would end a long session without telling the clients that signed in to it early.

SessionClientRegistry.GetClientsAsync(TenantDefinition, string, CancellationToken) Method

The clients recorded for a session, each once.

C#
public System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<string>> GetClientsAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition tenant, string sessionId, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

tenant TenantDefinition

The tenant the session belongs to.

sessionId System.String

The session.

cancellationToken System.Threading.CancellationToken

Cancels the lookup.

Implements GetClientsAsync(TenantDefinition, string, CancellationToken)

Returns

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<System.String>>
The recorded client identifiers; empty when none are recorded or the records have expired.