do sessions in memory and also fix glaring security hole
This commit is contained in:
parent
7b6c155a73
commit
f48b421500
31 changed files with 441 additions and 440 deletions
30
Femto.Modules.Auth/Infrastructure/SessionStorage.cs
Normal file
30
Femto.Modules.Auth/Infrastructure/SessionStorage.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using Femto.Modules.Auth.Models;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace Femto.Modules.Auth.Infrastructure;
|
||||
|
||||
internal class SessionStorage(MemoryCacheOptions? options = null)
|
||||
{
|
||||
private readonly IMemoryCache _storage = new MemoryCache(options ?? new MemoryCacheOptions());
|
||||
|
||||
public Task<Session?> GetSession(string id)
|
||||
{
|
||||
return Task.FromResult(this._storage.Get<Session>(id));
|
||||
}
|
||||
|
||||
public Task AddSession(Session session)
|
||||
{
|
||||
using var entry = this._storage.CreateEntry(session.Id);
|
||||
entry.Value = session;
|
||||
entry.SetAbsoluteExpiration(session.Expires);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task DeleteSession(string id)
|
||||
{
|
||||
this._storage.Remove(id);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue