Class SessionService
Manages user login sessions. Sessions track when a user logged into an application.
Revoking sessions cascades to revoking all authorizations (which invalidates tokens).
public sealed class SessionService
Inheritance
Methods
BindClientAsync(long, long, CancellationToken)
Records that applicationObjectId obtained tokens through session
public Task<bool> BindClientAsync(long sessionId, long applicationObjectId, CancellationToken ct = default)
CreateAsync(long, long, bool, string?, string?, string?, string?, CancellationToken)
Creates a new active session record. ipAddress, userAgent
public Task<RedbObject<SessionProps>> CreateAsync(long userId, long applicationObjectId, bool mfaVerified = false, string? mfaMethod = null, string? ipAddress = null, string? userAgent = null, string? deviceLabel = null, CancellationToken ct = default)
IsExpired(SessionProps, DateTimeOffset?, DateTimeOffset)
S-track: is this session beyond either timeout? Mirrors the check done
public bool IsExpired(SessionProps props, DateTimeOffset? createdAt, DateTimeOffset now)
IsFullyRevokedAsync(long, TimeSpan?, CancellationToken)
Checks whether the user's sessions have been revoked (indicating explicit logout).
public Task<bool> IsFullyRevokedAsync(long userId, TimeSpan? lookbackWindow = null, CancellationToken ct = default)
IsSessionRevokedAsync(long, CancellationToken)
Checks whether a specific session (by its object ID) has been revoked.
public Task<bool> IsSessionRevokedAsync(long sessionObjectId, CancellationToken ct = default)
ListAllActiveAsync(int, int, CancellationToken)
Admin-wide list of recent active sessions across ALL users, paginated.
public Task<(List<SessionService.SessionInfo> Items, int Total)> ListAllActiveAsync(int offset, int count, CancellationToken ct = default)
ListAsync(long, CancellationToken)
Lists all active sessions for a user. Includes application info.
public Task<List<SessionService.SessionInfo>> ListAsync(long userId, CancellationToken ct = default)
LogoutAsync(long, CancellationToken)
Signs the user out everywhere: every active session, every authorization and every valid token of
public Task<int> LogoutAsync(long userId, CancellationToken ct = default)
PreviewRevokeAllAsync(long, CancellationToken)
N7-4 dry-run: returns how many active sessions would
public Task<(int Count, IReadOnlyList<long> SampleSessionIds)> PreviewRevokeAllAsync(long userId, CancellationToken ct = default)
RevokeAllAsync(long, CancellationToken)
Revokes all active sessions for a user.
public Task<int> RevokeAllAsync(long userId, CancellationToken ct = default)
RevokeAsync(long, CancellationToken)
Revokes a single session by its object ID.
public Task<int> RevokeAsync(long sessionObjectId, CancellationToken ct = default)
TouchAsync(long, string, CancellationToken)
S-track: bump LastAccessedAt on the given session. Called by
public Task<bool> TouchAsync(long sessionId, string activity, CancellationToken ct = default)