Added expiration parameter to token generation

This commit is contained in:
Mia Rose Winter 2024-02-13 13:41:11 +01:00
parent 68c7dfda39
commit e8438c5050
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -15,7 +15,7 @@ public enum Constants {
private Regex TokenMatcher { get; } = MyRegex();
public async Task<(string user, string token)> CreateConfirmTokensAsync(Guid subscriberId, string role = "subscribe") {
public async Task<(string user, string token)> CreateConfirmTokensAsync(Guid subscriberId, string role = "subscribe", TimeSpan? expiration = null) {
string user = Convert.ToBase64String(subscriberId.ToByteArray());
string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
string cacheKey = role + "-" + user;
@ -23,7 +23,7 @@ public enum Constants {
await TokenCache.SetAsync(cacheKey,
Convert.FromBase64String(token),
new DistributedCacheEntryOptions {
AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(1)
AbsoluteExpirationRelativeToNow = expiration ?? TimeSpan.FromDays(1)
});
return (user, token);