Class PanelSessionManager
- Namespace
- FishMMO.ControlPanel.Auth
- Assembly
- FishMMO-ControlPanel.dll
Issues, validates and revokes Control Panel browser sessions.
public sealed class PanelSessionManager
- Inheritance
-
PanelSessionManager
- Inherited Members
Remarks
The browser holds an opaque 32-byte identifier; the database holds only its SHA-256, so a
database read does not yield usable sessions. The identifier is delivered as a cookie that
is HttpOnly, Secure, SameSite=Strict and host-scoped to the panel.
Elevated sessions get shorter lifetimes than player sessions, on the principle that the blast radius of a stolen operator session is the whole shard.
Constructors
PanelSessionManager(IWebSessionService)
public PanelSessionManager(IWebSessionService sessions)
Parameters
sessionsIWebSessionService
Fields
CookieName
Name of the session cookie.
public const string CookieName = "fishmmo_panel_session"
Field Value
Methods
BuildCookieOptions(DateTime, bool)
Cookie options for the session cookie.
public static CookieOptions BuildCookieOptions(DateTime expiresUtc, bool isDevelopment)
Parameters
Returns
Hash(string)
Hashes a session identifier the way the store expects.
public static string Hash(string sessionId)
Parameters
sessionIdstring
Returns
IdleTimeoutFor(byte)
Idle timeout that applies at a given access level.
public static TimeSpan IdleTimeoutFor(byte accessLevel)
Parameters
accessLevelbyte
Returns
IssueAsync(string, byte, bool, string, string, CancellationToken)
Issues a session and returns the raw identifier for the cookie. The identifier is returned exactly once and never stored.
public Task<(bool Ok, string SessionId, WebSessionData Session, string Error)> IssueAsync(string accountName, byte accessLevel, bool twoFactorSatisfied, string ipAddress, string userAgent, CancellationToken cancellationToken = default)
Parameters
accountNamestringaccessLevelbytetwoFactorSatisfiedboolipAddressstringuserAgentstringcancellationTokenCancellationToken
Returns
LifetimeFor(byte)
Absolute lifetime that applies at a given access level.
public static TimeSpan LifetimeFor(byte accessLevel)
Parameters
accessLevelbyte
Returns
PromoteAsync(string, byte, CancellationToken)
Promotes a pending session once its second factor is proven, extending it to the account's real lifetime.
public Task<bool> PromoteAsync(string hash, byte accessLevel, CancellationToken cancellationToken = default)
Parameters
hashstringaccessLevelbytecancellationTokenCancellationToken
Returns
Remarks
The result is returned rather than discarded. Swallowing it meant a promotion could fail while the endpoint still answered "signed in", leaving the operator with a session that every subsequent policy check refused.
RevokeAllAsync(string, CancellationToken)
Revokes every session for an account, returning how many rows changed.
public Task<DatabaseResult<int>> RevokeAllAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringcancellationTokenCancellationToken
Returns
RevokeAsync(string, CancellationToken)
Revokes one session.
public Task<bool> RevokeAsync(string hash, CancellationToken cancellationToken = default)
Parameters
hashstringcancellationTokenCancellationToken
Returns
Remarks
Returned rather than swallowed, for the reason PromoteAsync(string, byte, CancellationToken) gives: this used to be
typed Task, which made the result unobservable, and sign-out answered success while
the session row lived on.
StepUpAsync(string, CancellationToken)
Records a fresh step-up.
public Task<bool> StepUpAsync(string hash, CancellationToken cancellationToken = default)
Parameters
hashstringcancellationTokenCancellationToken
Returns
TouchAsync(string, CancellationToken)
Stamps activity on a live session.
public Task TouchAsync(string hash, CancellationToken cancellationToken = default)
Parameters
hashstringcancellationTokenCancellationToken
Returns
ValidateAsync(string, CancellationToken)
Loads a session by its raw identifier and applies the revoked, expiry and idle checks.
public Task<(PanelSessionManager.Validity Result, WebSessionData Session, string Hash)> ValidateAsync(string sessionId, CancellationToken cancellationToken = default)
Parameters
sessionIdstringcancellationTokenCancellationToken
Returns
Remarks
A session past its idle timeout is revoked here rather than merely refused, so an abandoned browser cannot be resurrected by a stolen cookie inside the absolute window.
A failed read is Unavailable, never Invalid. Treating the two alike made the handler delete the cookie of every operator whose request arrived during a database blip, signing the whole staff out of the panel they needed during the incident.