Class WebSessionService
Control Panel browser sessions, stored by hash.
public sealed class WebSessionService : BaseService<WebSessionEntity>, IWebSessionService
- Inheritance
-
WebSessionService
- Implements
- Inherited Members
Remarks
Every statement goes through EF rather than raw SQL, deliberately: the model carries the
configured schema via HasDefaultSchema, but a raw UPDATE web_sessions ... is
resolved against the connection's search_path instead. On any deployment whose
Npgsql:Schema is not the search path, those statements silently matched nothing and
the failure was swallowed by callers that ignored the result — a session could be issued
and then never promoted, revoked or expired.
Constructors
WebSessionService(INpgsqlDbContextFactory)
public WebSessionService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactory
Methods
CleanupExpiredAsync(DateTime, CancellationToken)
Deletes sessions that expired before the cutoff. Returns how many rows went.
public Task<DatabaseResult<int>> CleanupExpiredAsync(DateTime cutoffUtc, CancellationToken cancellationToken = default)
Parameters
cutoffUtcDateTimecancellationTokenCancellationToken
Returns
FetchActiveForAccountAsync(string, CancellationToken)
Lists the live sessions for an account, newest first.
public Task<DatabaseResult<List<WebSessionData>>> FetchActiveForAccountAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringcancellationTokenCancellationToken
Returns
FetchByHashAsync(string, CancellationToken)
Fetches a session by hash. Returns failure when it does not exist; the caller still has to apply the revoked, expiry and idle checks.
public Task<DatabaseResult<WebSessionData>> FetchByHashAsync(string sessionHash, CancellationToken cancellationToken = default)
Parameters
sessionHashstringcancellationTokenCancellationToken
Returns
IssueAsync(string, string, byte, bool, DateTime, string, string, CancellationToken)
Records a newly issued session.
public Task<DatabaseResult<WebSessionData>> IssueAsync(string sessionHash, string accountName, byte accessLevel, bool twoFactorSatisfied, DateTime expiresUtc, string ipAddress, string userAgent, CancellationToken cancellationToken = default)
Parameters
sessionHashstringSHA-256 hex of the session identifier.
accountNamestringAccount the session authenticates.
accessLevelbyteThe account's access level at issue.
twoFactorSatisfiedboolWhether two-factor is already satisfied.
expiresUtcDateTimeAbsolute expiry.
ipAddressstringClient address, or null.
userAgentstringClient user agent, or null.
cancellationTokenCancellationTokenCancellation token.
Returns
PersistStepUpAsync(string, CancellationToken)
Stamps a fresh step-up, restarting the window for destructive actions.
public Task<DatabaseResult> PersistStepUpAsync(string sessionHash, CancellationToken cancellationToken = default)
Parameters
sessionHashstringcancellationTokenCancellationToken
Returns
PersistTwoFactorSatisfiedAsync(string, DateTime, CancellationToken)
Marks two-factor satisfied and stamps the step-up time, promoting a pending session.
public Task<DatabaseResult> PersistTwoFactorSatisfiedAsync(string sessionHash, DateTime expiresUtc, CancellationToken cancellationToken = default)
Parameters
sessionHashstringexpiresUtcDateTimecancellationTokenCancellationToken
Returns
RevokeAllForAccountAsync(string, CancellationToken)
Revokes every session for an account. Called when the account is banned, its access level changes, its password changes, or its tokens are revoked.
public Task<DatabaseResult<int>> RevokeAllForAccountAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringcancellationTokenCancellationToken
Returns
RevokeByHashAsync(string, CancellationToken)
Revokes one session.
public Task<DatabaseResult> RevokeByHashAsync(string sessionHash, CancellationToken cancellationToken = default)
Parameters
sessionHashstringcancellationTokenCancellationToken
Returns
RevokeByIdAsync(string, long, CancellationToken)
Revokes one session by its surrogate id, for the operator's session list.
public Task<DatabaseResult> RevokeByIdAsync(string accountName, long id, CancellationToken cancellationToken = default)
Parameters
accountNamestringidlongcancellationTokenCancellationToken
Returns
TouchAsync(string, CancellationToken)
Stamps last-seen on a live session, extending its idle window.
public Task<DatabaseResult> TouchAsync(string sessionHash, CancellationToken cancellationToken = default)
Parameters
sessionHashstringcancellationTokenCancellationToken