Added role parameter to token generation

This commit is contained in:
Mia Rose Winter 2024-02-13 13:40:18 +01:00
parent 332abae312
commit 68c7dfda39
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -15,10 +15,10 @@ public enum Constants {
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 token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
string cacheKey = "subscribe-" + user;
string cacheKey = role + "-" + user;
await TokenCache.SetAsync(cacheKey,
Convert.FromBase64String(token),
@ -29,8 +29,8 @@ public enum Constants {
return (user, token);
}
public async Task<Guid?> ValidateTokensAsync(string user, string token) {
string cacheKey = "subscribe-" + user;
public async Task<Guid?> ValidateTokensAsync(string user, string token, string role = "subscribe") {
string cacheKey = role + "-" + user;
byte[]? tokenInCache = await TokenCache.GetAsync(cacheKey);
if (tokenInCache is null || token != Convert.ToBase64String(tokenInCache))