Added role parameter to token generation
This commit is contained in:
parent
332abae312
commit
68c7dfda39
|
@ -15,10 +15,10 @@ public enum Constants {
|
||||||
|
|
||||||
private Regex TokenMatcher { get; } = MyRegex();
|
private Regex TokenMatcher { get; } = MyRegex();
|
||||||
|
|
||||||
public async Task<(string user, string token)> CreateConfirmTokensAsync(Guid subscriberId) {
|
public async Task<(string user, string token)> CreateConfirmTokensAsync(Guid subscriberId, string role = "subscribe") {
|
||||||
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 = "subscribe-" + user;
|
string cacheKey = role + "-" + user;
|
||||||
|
|
||||||
await TokenCache.SetAsync(cacheKey,
|
await TokenCache.SetAsync(cacheKey,
|
||||||
Convert.FromBase64String(token),
|
Convert.FromBase64String(token),
|
||||||
|
@ -29,8 +29,8 @@ public enum Constants {
|
||||||
return (user, token);
|
return (user, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Guid?> ValidateTokensAsync(string user, string token) {
|
public async Task<Guid?> ValidateTokensAsync(string user, string token, string role = "subscribe") {
|
||||||
string cacheKey = "subscribe-" + user;
|
string cacheKey = role + "-" + user;
|
||||||
byte[]? tokenInCache = await TokenCache.GetAsync(cacheKey);
|
byte[]? tokenInCache = await TokenCache.GetAsync(cacheKey);
|
||||||
|
|
||||||
if (tokenInCache is null || token != Convert.ToBase64String(tokenInCache))
|
if (tokenInCache is null || token != Convert.ToBase64String(tokenInCache))
|
||||||
|
|
Loading…
Reference in a new issue