Added expiration parameter to token generation
This commit is contained in:
parent
68c7dfda39
commit
e8438c5050
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue