added auth with a simple UI
This commit is contained in:
32
api/OED.Api/Infrastructure/Auth/SessionService.cs
Normal file
32
api/OED.Api/Infrastructure/Auth/SessionService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Text.Json;
|
||||
using OED.Api.Core.Interfaces.Services;
|
||||
using OED.Api.Core.Models.Eve;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace OED.Api.Infrastructure.Auth;
|
||||
|
||||
public class SessionService(IConnectionMultiplexer redis) : ISessionService
|
||||
{
|
||||
private readonly IDatabase _db = redis.GetDatabase();
|
||||
private static readonly TimeSpan SessionTtl = TimeSpan.FromDays(7);
|
||||
|
||||
public async Task<string> CreateAsync(EveSession session)
|
||||
{
|
||||
var sessionId = Guid.NewGuid().ToString("N");
|
||||
var json = JsonSerializer.Serialize(session);
|
||||
await _db.StringSetAsync($"session:{sessionId}", json, SessionTtl);
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public async Task<EveSession?> GetAsync(string sessionId)
|
||||
{
|
||||
var json = await _db.StringGetAsync($"session:{sessionId}");
|
||||
if (json.IsNullOrEmpty) return null;
|
||||
return JsonSerializer.Deserialize<EveSession>((string)json!);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string sessionId)
|
||||
{
|
||||
await _db.KeyDeleteAsync($"session:{sessionId}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user