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
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
maxClientCountintThe most devices that may use it at once, or 0 for no limit. The default is 1.
tokenNamestringIts name, or null.
maxTrafficByteCountintIts traffic quota, in bytes, or 0, the default, for none.
expirationTimeDateTime?When it expires, in UTC, or null, the default, for never.
maxSpeedMbpsTraffic?Its speed limits each way, in megabits a second, or null, the default, for none.
adRequirementAdRequirementThe ad it asks for (AdRequirement). The default is none.
Returns
- Task<AccessToken>
A task whose result is the access key.
Exceptions
- OperationCanceledException
cancellationTokenwas 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
tokenIdstringThe access key's ID.
cancellationTokenCancellationTokenThe 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
tokenIdhas a character no file name may.- OperationCanceledException
cancellationTokenwas canceled.
GetTotalCount()
Counts the access keys, by their files.
public Task<int> GetTotalCount()