Add hashing and other security features #12

Merged
Wesser merged 45 commits from feat/add-security into feat/add-setup 2024-05-29 06:42:47 +03:00
Showing only changes of commit f4ad1518ef - Show all commits

View File

@ -17,26 +17,28 @@ public class PreAuthService(ICacheService cache)
GeneratorKey.GenerateString(16); GeneratorKey.GenerateString(16);
private static string GetPreAuthCacheKey(string fingerprint) => $"{fingerprint}_pre_auth_token"; private static string GetPreAuthCacheKey(string fingerprint) => $"{fingerprint}_pre_auth_token";
{
var firstAuthToken = GenerateFirstAuthToken();
var loginStructure = new PreAuthToken public async Task<PreAuthTokenResponse> GeneratePreAuthTokenAsync(TokenRequest request, string userId, CancellationToken cancellation = default)
{
var preAuthToken = GeneratePreAuthToken();
var preAuthTokenStruct = new PreAuthToken
{ {
Fingerprint = request.Fingerprint, Fingerprint = request.Fingerprint,
UserId = userId, UserId = userId,
UserAgent = request.UserAgent, UserAgent = request.UserAgent,
Token = firstAuthToken Token = preAuthToken
}; };
await cache.SetAsync( await cache.SetAsync(
GetPreAuthCacheKey(request.Fingerprint), GetPreAuthCacheKey(request.Fingerprint),
JsonSerializer.SerializeToUtf8Bytes(loginStructure), JsonSerializer.SerializeToUtf8Bytes(preAuthTokenStruct),
Lifetime, Lifetime,
cancellation); cancellation);
return new PreAuthTokenResponse return new PreAuthTokenResponse
{ {
Token = firstAuthToken, Token = preAuthToken,
ExpiresIn = DateTime.UtcNow.Add(Lifetime) ExpiresIn = DateTime.UtcNow.Add(Lifetime)
}; };
} }