Table of Contents

Class AuthTokenService

Namespace
FishMMO.Database.Npgsql.Services
Assembly
FishMMO-DB.dll

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

dbContextFactory INpgsqlDbContextFactory

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

cutoffUtc DateTime
cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

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

tokenHash string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<AuthTokenData>>

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

tokenHash string

SHA-256 hex hash of the signed token blob.

accountName string

The account the token was issued for.

loginServerId long

The LoginServer that issued the token.

expiresUtc DateTime

When the token expires.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<AuthTokenData>>

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> RevokeAllForAccountAsync(string accountName, CancellationToken cancellationToken = default)

Parameters

accountName string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

RevokeByHashAsync(string, CancellationToken)

Revokes a specific token by its hash.

public Task<DatabaseResult> RevokeByHashAsync(string tokenHash, CancellationToken cancellationToken = default)

Parameters

tokenHash string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>