- **docker-compose.yml** - Added Redis service configuration to support token storage. - Set up health checks and volume for Redis persistence. - Configured VRCAuthProxy service to depend on Redis. - **HttpClientCookieContainer.cs** - Added `Username` property to support user-specific token management. - **Program.cs** - Integrated Redis for storing and retrieving authentication tokens. - Updated login and token rotation logic to utilize Redis. - Improved async/await usage for better reliability. - **VRCAuthProxy.csproj** - Added `StackExchange.Redis` package for Redis connectivity. - Corrected `Otp.NET` package reference. - **API.cs** - Updated `TotpVerifyResponse` and `User` classes to be nullable-aware. - **RedisService.cs** - Implemented Redis service for managing authentication tokens. - Added methods for saving, retrieving, and deleting tokens.
52 lines
No EOL
1.6 KiB
C#
52 lines
No EOL
1.6 KiB
C#
using System.Text.Json;
|
|
using StackExchange.Redis;
|
|
|
|
namespace VRCAuthProxy.Services;
|
|
|
|
public class RedisService
|
|
{
|
|
private readonly IConnectionMultiplexer _redis;
|
|
private readonly IDatabase _db;
|
|
private const string AUTH_TOKEN_KEY = "vrcauthproxy:tokens";
|
|
|
|
public RedisService(string connectionString)
|
|
{
|
|
_redis = ConnectionMultiplexer.Connect(connectionString);
|
|
_db = _redis.GetDatabase();
|
|
}
|
|
|
|
public async Task SaveAuthToken(string username, Dictionary<string, string> cookies)
|
|
{
|
|
var serializedCookies = JsonSerializer.Serialize(cookies);
|
|
await _db.HashSetAsync(AUTH_TOKEN_KEY, username, serializedCookies);
|
|
}
|
|
|
|
public async Task<Dictionary<string, string>?> GetAuthToken(string username)
|
|
{
|
|
var value = await _db.HashGetAsync(AUTH_TOKEN_KEY, username);
|
|
if (!value.HasValue) return null;
|
|
return JsonSerializer.Deserialize<Dictionary<string, string>>(value!);
|
|
}
|
|
|
|
public async Task<Dictionary<string, Dictionary<string, string>>> GetAllAuthTokens()
|
|
{
|
|
var entries = await _db.HashGetAllAsync(AUTH_TOKEN_KEY);
|
|
var result = new Dictionary<string, Dictionary<string, string>>();
|
|
|
|
foreach (var entry in entries)
|
|
{
|
|
var cookies = JsonSerializer.Deserialize<Dictionary<string, string>>(entry.Value!);
|
|
if (cookies != null)
|
|
{
|
|
result[entry.Name!] = cookies;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task RemoveAuthToken(string username)
|
|
{
|
|
await _db.HashDeleteAsync(AUTH_TOKEN_KEY, username);
|
|
}
|
|
} |