Class AuthTokenService
Service for managing authentication tokens. The LoginServer issues tokens; WorldServers and SceneServers validate and check revocation. Uses compiled queries for the hot validation path and raw SQL for writes.
public sealed class AuthTokenService : BaseService<AuthTokenEntity>, IAuthTokenService
- Inheritance
-
AuthTokenService
- Implements
- Inherited Members
Constructors
AuthTokenService(INpgsqlDbContextFactory)
public AuthTokenService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactory
Methods
CleanupExpiredAsync(DateTime, CancellationToken)
Deletes expired tokens older than the specified cutoff. Returns the number of tokens deleted. Called periodically for database maintenance.
public Task<DatabaseResult<int>> CleanupExpiredAsync(DateTime cutoffUtc, CancellationToken cancellationToken = default)
Parameters
cutoffUtcDateTimecancellationTokenCancellationToken
Returns
FetchByHashAsync(string, CancellationToken)
Fetches a token record by its hash for revocation checks. Returns failure if the token is not found.
public Task<DatabaseResult<AuthTokenData>> FetchByHashAsync(string tokenHash, CancellationToken cancellationToken = default)
Parameters
tokenHashstringcancellationTokenCancellationToken
Returns
IssueAsync(string, string, long, DateTime, CancellationToken)
Records a newly issued authentication token. Called by the LoginServer after successful SRP authentication.
public Task<DatabaseResult<AuthTokenData>> IssueAsync(string tokenHash, string accountName, long loginServerId, DateTime expiresUtc, CancellationToken cancellationToken = default)
Parameters
tokenHashstringSHA-256 hex hash of the signed token blob.
accountNamestringThe account the token was issued for, in any case: it is recorded as the account row's own (lowercase) name, which the column references.
loginServerIdlongThe LoginServer that issued the token.
expiresUtcDateTimeWhen the token expires.
cancellationTokenCancellationTokenCancellation token.
Returns
RevokeAllForAccountAsync(string, CancellationToken)
Revokes all active tokens for a specific account. Used when an account is banned, password is changed, or force-logout is required.
public Task<DatabaseResult<int>> RevokeAllForAccountAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringThe account, in any case: matched the way accounts are looked up.
cancellationTokenCancellationToken
Returns
- Task<DatabaseResult<int>>
How many tokens were revoked; zero when the account had none live.
RevokeByHashAsync(string, CancellationToken)
Revokes a specific token by its hash.
public Task<DatabaseResult> RevokeByHashAsync(string tokenHash, CancellationToken cancellationToken = default)
Parameters
tokenHashstringcancellationTokenCancellationToken