Class InMemoryServerSideSessionStore
- Namespace
- Fdyay.IdentityServer.Stores.InMemory
- Assembly
- Fdyay.IdentityServer.Core.dll
In-memory server-side session store. Intended for development and testing.
public class InMemoryServerSideSessionStore : IServerSideSessionStore
- Inheritance
-
InMemoryServerSideSessionStore
- Implements
- Inherited Members
Remarks
Sessions do not survive a restart here, and are not shared between instances — so a host running more than one process needs a real store, or a user will appear signed out whenever the load balancer moves them.
Constructors
InMemoryServerSideSessionStore()
A store on the system clock.
public InMemoryServerSideSessionStore()
InMemoryServerSideSessionStore(TimeProvider)
A store on the server's clock. Duende's constructor.
public InMemoryServerSideSessionStore(TimeProvider time)
Parameters
timeTimeProviderThe clock the expiry sweep judges Expires against.
Remarks
Since 0.175.0, and the one the container builds; until then the sweep read UtcNow.
Methods
CreateSessionAsync(ServerSideSession, CancellationToken)
Stores a session under its Key, replacing any already held under that key.
public Task CreateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default)
Parameters
sessionServerSideSessionThe session.
cancellationTokenCancellationTokenCancels the write.
Returns
DeleteSessionAsync(string, CancellationToken)
Removes the session stored under a key. A key with nothing stored under it is not an error.
public Task DeleteSessionAsync(string key, CancellationToken cancellationToken = default)
Parameters
keystringThe session's Key.
cancellationTokenCancellationTokenCancels the removal.
Returns
DeleteSessionsAsync(SessionFilter, CancellationToken)
Ends every session matching the filter.
public Task DeleteSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default)
Parameters
filterSessionFiltercancellationTokenCancellationToken
Returns
GetAndRemoveExpiredSessionsAsync(int, CancellationToken)
Removes sessions past their expiry and returns them, so a caller can act on what it removed.
public Task<IReadOnlyCollection<ServerSideSession>> GetAndRemoveExpiredSessionsAsync(int count, CancellationToken cancellationToken = default)
Parameters
countintcancellationTokenCancellationToken
Returns
Remarks
Returns rather than merely deletes because an expired session still has clients that were signed in to it, and they are owed a back-channel logout. A sweep that deleted silently would leave every relying party believing a session that ended hours ago is still live.
GetSessionAsync(string, CancellationToken)
The session stored under a key, or null.
public Task<ServerSideSession?> GetSessionAsync(string key, CancellationToken cancellationToken = default)
Parameters
keystringThe session's Key.
cancellationTokenCancellationTokenCancels the read.
Returns
- Task<ServerSideSession>
The session, or null when none is stored under that key.
GetSessionsAsync(SessionFilter, CancellationToken)
Every session matching the filter.
public Task<IReadOnlyCollection<ServerSideSession>> GetSessionsAsync(SessionFilter filter, CancellationToken cancellationToken = default)
Parameters
filterSessionFiltercancellationTokenCancellationToken
Returns
QuerySessionsAsync(SessionQuery, CancellationToken)
A page of sessions, for an administrative list.
public Task<QueryResult<ServerSideSession>> QuerySessionsAsync(SessionQuery query, CancellationToken cancellationToken = default)
Parameters
querySessionQuerycancellationTokenCancellationToken
Returns
UpdateSessionAsync(ServerSideSession, CancellationToken)
Replaces the session stored under its Key, or stores it when none is.
public Task UpdateSessionAsync(ServerSideSession session, CancellationToken cancellationToken = default)
Parameters
sessionServerSideSessionThe session as it now stands.
cancellationTokenCancellationTokenCancels the write.