Table of Contents

Class AccessTokenService

Namespace
VpnHood.Core.Server.Access.Managers.FileAccessManagers.Services
Assembly
VpnHood.Core.Server.Access.Managers.FileAccessManagers.dll

Provides a file access manager's access keys, each in a file of its own beside its usage.

public class AccessTokenService
Inheritance
AccessTokenService
Inherited Members

Methods

Create(CancellationToken, int, string?, int, DateTime?, Traffic?, AdRequirement)

Makes an access key, with a new ID and secret, and writes it to its file.

public Task<AccessToken> Create(CancellationToken cancellationToken, int maxClientCount = 1, string? tokenName = null, int maxTrafficByteCount = 0, DateTime? expirationTime = null, Traffic? maxSpeedMbps = null, AdRequirement adRequirement = AdRequirement.None)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

maxClientCount int

The most devices that may use it at once, or 0 for no limit. The default is 1.

tokenName string

Its name, or null.

maxTrafficByteCount int

Its traffic quota, in bytes, or 0, the default, for none.

expirationTime DateTime?

When it expires, in UTC, or null, the default, for never.

maxSpeedMbps Traffic?

Its speed limits each way, in megabits a second, or null, the default, for none.

adRequirement AdRequirement

The ad it asks for (AdRequirement). The default is none.

Returns

Task<AccessToken>

A task whose result is the access key.

Exceptions

OperationCanceledException

cancellationToken was canceled.

IOException

The file could not be written.

Get(string, CancellationToken)

Gets an access key with its usage, from the cache or else from its files.

public Task<AccessTokenData> Get(string tokenId, CancellationToken cancellationToken)

Parameters

tokenId string

The access key's ID.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<AccessTokenData>

A task whose result is the access key with its usage.

Exceptions

KeyNotFoundException

There is no such access key.

JsonException

The access key's file holds malformed JSON, or JSON that cannot be read as an access key.

InvalidDataException

The access key's file holds null.

InvalidOperationException

tokenId has a character no file name may.

OperationCanceledException

cancellationToken was canceled.

GetTotalCount()

Counts the access keys, by their files.

public Task<int> GetTotalCount()

Returns

Task<int>

A task whose result is the count.