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();
|
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 user = Convert.ToBase64String(subscriberId.ToByteArray());
|
||||||
string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
|
string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
|
||||||
string cacheKey = role + "-" + user;
|
string cacheKey = role + "-" + user;
|
||||||
|
@ -23,7 +23,7 @@ public enum Constants {
|
||||||
await TokenCache.SetAsync(cacheKey,
|
await TokenCache.SetAsync(cacheKey,
|
||||||
Convert.FromBase64String(token),
|
Convert.FromBase64String(token),
|
||||||
new DistributedCacheEntryOptions {
|
new DistributedCacheEntryOptions {
|
||||||
AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(1)
|
AbsoluteExpirationRelativeToNow = expiration ?? TimeSpan.FromDays(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
return (user, token);
|
return (user, token);
|
||||||
|
|
Loading…
Reference in a new issue