Upgraded projects to .NET 9.0 and added new projects `KBR.Cache`, `KBR.Shared`, and `KBR.Shared.Lite` to the solution. Introduced JWT authentication and OTP handling with new models, services, and configuration options. Updated database schema with new entities `Users` and `RefreshTokens`, and added migrations for schema changes. Implemented caching strategies using `AppDistributedCache` with support for in-memory, SQL Server, and Redis. Enhanced email handling with `MailHelpers` for domain replacement. Updated controllers, repositories, and configuration files to support new features.
24 lines
984 B
C#
24 lines
984 B
C#
using KBR.Shared.Cache.Models;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
|
|
namespace KBR.Cache
|
|
{
|
|
public static class CacheHelpers
|
|
{
|
|
private static readonly string _userOtpSecrets = nameof(_userOtpSecrets);
|
|
|
|
private static string UserOtpSecretKey(string key) => $"{_userOtpSecrets}-{key}";
|
|
|
|
public static async Task SetUserSecretsCacheAsync(IAppDistributedCache cache, string userId, string secret, CancellationToken cancellationToken = default)
|
|
{
|
|
await cache.SetAsync(UserOtpSecretKey(userId), secret, new DistributedCacheEntryOptions { AbsoluteExpiration = DateTime.UtcNow.AddMinutes(3) }, cancellationToken);
|
|
}
|
|
|
|
public static async Task<string> GetUserOtpSecretAsync(IAppDistributedCache cache, string userId, CancellationToken cancellationToken = default)
|
|
{
|
|
var key = await cache.GetAsync<string>(UserOtpSecretKey(userId), cancellationToken);
|
|
|
|
return key;
|
|
}
|
|
}
|
|
} |